📖 Scenario: You are automating a software deployment process using Jenkins. Before deploying to production, you want a human to review and approve the deployment manually.
🎯 Goal: Create a Jenkins pipeline script that pauses for manual approval using the input step before continuing to the deployment stage.
📋 What You'll Learn
Create a Jenkins pipeline script with a stage named Approval
Use the input step to pause the pipeline and ask for manual approval
After approval, print a message indicating deployment will proceed
💡 Why This Matters
🌍 Real World
Manual approval steps are common in deployment pipelines to ensure safety before releasing to production.
💼 Career
DevOps engineers often implement manual gates in CI/CD pipelines to balance automation with human oversight.
Progress0 / 4 steps
1
Create a basic Jenkins pipeline skeleton
Write a Jenkins pipeline script with a pipeline block and an empty stages section.
Jenkins
Hint
Start with the basic Jenkins pipeline structure including pipeline, agent any, and stages blocks.
2
Add an Approval stage with an input step
Inside the stages block, add a stage named Approval that uses the input step with the message 'Approve deployment?'.
Jenkins
Hint
Use stage('Approval') and inside steps, add input message: 'Approve deployment?'.
3
Add a deployment stage that runs after approval
Add another stage named Deploy after the Approval stage. Inside steps, add a echo statement that prints 'Deployment started'.
Jenkins
Hint
Add a new stage Deploy with a step that echoes 'Deployment started'.
4
Print confirmation after manual approval
Add a script block inside the Deploy stage's steps to print 'Deployment approved and started' using echo.
Jenkins
Hint
Wrap the echo command inside a script block to print the confirmation message.
Practice
(1/5)
1. What is the main purpose of the input step in a Jenkins pipeline?
easy
A. To send email notifications
B. To automatically deploy the application
C. To run tests in parallel
D. To pause the pipeline and wait for manual approval
Solution
Step 1: Understand the role of the input step
The input step is designed to pause the pipeline execution and wait for a user to approve or reject the continuation.
Step 2: Compare with other pipeline actions
Other options like deployment, testing, or notifications are handled by different steps, not input.
Final Answer:
To pause the pipeline and wait for manual approval -> Option D
Quick Check:
Input step = manual pause [OK]
Hint: Input step always waits for user action [OK]
Common Mistakes:
Confusing input with automated steps
Thinking input triggers deployment
Assuming input sends notifications
2. Which of the following is the correct syntax to add a manual approval input step in a Jenkins declarative pipeline?
easy
A. input message: 'Approve deployment?'
B. input('Approve deployment?')
C. input { message: 'Approve deployment?' }
D. input message = 'Approve deployment?'
Solution
Step 1: Recall Jenkins input step syntax
The correct syntax uses the input step with named parameters like message: 'text'.
Step 2: Check each option
input message: 'Approve deployment?' matches the correct syntax. Options A, B, and D use incorrect formats or braces.
Final Answer:
input message: 'Approve deployment?' -> Option A
Quick Check:
Correct input syntax uses named parameters [OK]
Hint: Use named parameters with colon for input step [OK]
Common Mistakes:
Using parentheses instead of named parameters
Using braces instead of parentheses
Assigning message with equals sign
3. Given the following Jenkins scripted pipeline snippet, what will happen when it reaches the input step?
In declarative pipelines, the input step must be wrapped inside a script block to run scripted steps.
Step 2: Check the snippet
The input step is directly inside steps without script, causing a syntax error.
Final Answer:
The input step must be inside a script block in declarative pipeline -> Option C
Quick Check:
Input in declarative needs script block [OK]
Hint: Wrap input step in script block in declarative pipelines [OK]
Common Mistakes:
Placing input step directly in steps without script
Missing quotes around message
Thinking input can't be used in certain stages
5. You want to add a manual approval step in a Jenkins declarative pipeline that asks the user to confirm deployment with a custom message and a timeout of 1 hour. Which snippet correctly implements this?
hard
A. input message: 'Deploy now?', timeout: 3600
B. script { input message: 'Deploy now?', timeout: 3600 }