Input step for manual approval in Jenkins - Time & Space Complexity
We want to understand how the time taken by a Jenkins pipeline changes when it includes a manual approval step.
Specifically, how does waiting for user input affect the overall execution time?
Analyze the time complexity of the following Jenkins pipeline snippet with a manual approval step.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Approval') {
steps {
input message: 'Approve deployment?', ok: 'Yes'
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
}
}
}
}
This pipeline runs a build, then waits for manual approval before deploying.
Look for loops or repeated actions that affect time.
- Primary operation: The pipeline waits once for manual approval.
- How many times: Exactly one input step pause per pipeline run.
The waiting time depends on how long a person takes to approve, not on input size.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Build + 1 approval wait + Deploy |
| 100 | Build + 1 approval wait + Deploy |
| 1000 | Build + 1 approval wait + Deploy |
Pattern observation: The manual approval wait does not grow with input size; it is a fixed pause.
Time Complexity: O(1)
This means the waiting time for manual approval stays the same regardless of input size.
[X] Wrong: "The manual approval step makes the pipeline time grow with the number of builds."
[OK] Correct: Each pipeline run waits once for approval; the wait time does not multiply by input size within a single run.
Understanding how manual steps affect pipeline timing helps you design efficient workflows and explain delays clearly.
What if we added a loop that asks for approval multiple times in one pipeline run? How would the time complexity change?
Practice
input step in a Jenkins pipeline?Solution
Step 1: Understand the role of the input step
Theinputstep 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, notinput.Final Answer:
To pause the pipeline and wait for manual approval -> Option DQuick Check:
Input step = manual pause [OK]
- Confusing input with automated steps
- Thinking input triggers deployment
- Assuming input sends notifications
Solution
Step 1: Recall Jenkins input step syntax
The correct syntax uses theinputstep with named parameters likemessage: '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 AQuick Check:
Correct input syntax uses named parameters [OK]
- Using parentheses instead of named parameters
- Using braces instead of parentheses
- Assigning message with equals sign
input step?
node {
stage('Build') {
echo 'Building...'
}
stage('Approval') {
input message: 'Proceed with deployment?'
}
stage('Deploy') {
echo 'Deploying...'
}
}Solution
Step 1: Analyze the input step behavior
Theinputstep pauses the pipeline and waits for a user to approve before continuing.Step 2: Understand pipeline flow
After approval, the pipeline proceeds to the Deploy stage. Without approval, it stays paused.Final Answer:
Pipeline pauses and waits for user approval before deploying -> Option AQuick Check:
Input step pauses pipeline = Pipeline pauses and waits for user approval before deploying [OK]
- Assuming input step is skipped automatically
- Thinking input causes syntax error
- Believing pipeline runs all stages without pause
pipeline {
agent any
stages {
stage('Test') {
steps {
input message: 'Approve test run?'
echo 'Running tests...'
}
}
}
}Solution
Step 1: Understand declarative pipeline input usage
In declarative pipelines, theinputstep must be wrapped inside ascriptblock to run scripted steps.Step 2: Check the snippet
The input step is directly insidestepswithoutscript, causing a syntax error.Final Answer:
The input step must be inside a script block in declarative pipeline -> Option CQuick Check:
Input in declarative needs script block [OK]
- Placing input step directly in steps without script
- Missing quotes around message
- Thinking input can't be used in certain stages
Solution
Step 1: Understand timeout parameter unit
Thetimeoutparameter forinputis in seconds, so 1 hour = 3600 seconds.Step 2: Check declarative pipeline syntax
Input must be inside ascriptblock in declarative pipelines.Step 3: Evaluate options
script { input message: 'Deploy now?', timeout: 3600 } correctly usesscriptblock and timeout 3600 seconds. script { input message: 'Deploy now?', timeout: 60 } uses 60 (1 minute), B lacks script block, C adds submitter but timeout is 60 seconds.Final Answer:
script { input message: 'Deploy now?', timeout: 3600 } -> Option BQuick Check:
Timeout in seconds + script block = script { input message: 'Deploy now?', timeout: 3600 } [OK]
- Using timeout in minutes instead of seconds
- Omitting script block in declarative pipeline
- Adding unnecessary parameters
Ready to prove it?
Pass the test and this pattern moves unknown
