Consider this Jenkins pipeline snippet:
pipeline {
agent any
stages {
stage('Approval') {
steps {
script {
def userInput = input message: 'Approve deployment?', ok: 'Yes'
echo "User selected: ${userInput}"
}
}
}
}
}What will Jenkins print in the console after the user clicks 'Yes'?
pipeline {
agent any
stages {
stage('Approval') {
steps {
script {
def userInput = input message: 'Approve deployment?', ok: 'Yes'
echo "User selected: ${userInput}"
}
}
}
}
}Think about what the input step returns when the user clicks the OK button with label 'Yes'.
The input step returns the label of the button clicked by the user. Since the OK button is labeled 'Yes', the variable userInput will be 'Yes'.
You want to add a manual approval step in your Jenkins pipeline that waits for user input but times out after 5 minutes if no input is given. Which snippet achieves this?
Check the Jenkins input step documentation for the correct way to specify timeout in seconds.
The input step's timeout parameter expects an integer number of seconds. To set 5 minutes, use 300 seconds. Options B and C use invalid or unsupported parameters; D is only 5 seconds.
Given this snippet:
stage('Approval') {
steps {
input 'Approve deployment?'
echo 'Deployment approved'
}
}When running, Jenkins throws an error: java.lang.IllegalArgumentException: No valid parameters provided. What is the cause?
stage('Approval') { steps { input 'Approve deployment?' echo 'Deployment approved' } }
Check the required parameters for the input step in Jenkins pipeline.
The input step requires named parameters such as message: 'Approve deployment?'. A plain string is invalid and results in a "No valid parameters provided" error.
Consider this pipeline snippet:
stage('Approval') {
steps {
input message: 'Approve?', ok: 'Yes', timeout: 60
echo 'Approved'
}
}If no user input is given within 60 seconds, what is the pipeline behavior?
stage('Approval') { steps { input message: 'Approve?', ok: 'Yes', timeout: 60 echo 'Approved' } }
Think about what Jenkins does when a timeout occurs on an input step.
When the input step times out, Jenkins aborts the build with an error indicating the timeout. It does not continue or retry automatically.
You want to ask the user to select an environment to deploy to, with options 'dev', 'staging', and 'prod'. The pipeline should store the selected environment in a variable. Which snippet does this correctly?
Which parameter type allows selecting from multiple predefined options?
The choice parameter lets the user pick from a list of options. The other parameter types do not provide a dropdown selection.