0
0
Jenkinsdevops~20 mins

Input step for manual approval in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Manual Approval Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Jenkins pipeline snippet with input step?

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'?

Jenkins
pipeline {
  agent any
  stages {
    stage('Approval') {
      steps {
        script {
          def userInput = input message: 'Approve deployment?', ok: 'Yes'
          echo "User selected: ${userInput}"
        }
      }
    }
  }
}
AUser selected: false
BUser selected: true
CUser selected: Yes
DUser selected: null
Attempts:
2 left
💡 Hint

Think about what the input step returns when the user clicks the OK button with label 'Yes'.

Configuration
intermediate
2:00remaining
Which Jenkinsfile snippet correctly implements a manual approval with a timeout of 5 minutes?

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?

Ainput message: 'Approve?', ok: 'Proceed', timeout: 5, unit: 'MINUTES'
Binput message: 'Approve?', ok: 'Proceed', timeout: 300
Cinput message: 'Approve?', ok: 'Proceed', timeout: 5, timeoutUnit: 'MINUTES'
Dinput message: 'Approve?', ok: 'Proceed', timeout: 5
Attempts:
2 left
💡 Hint

Check the Jenkins input step documentation for the correct way to specify timeout in seconds.

Troubleshoot
advanced
2:00remaining
Why does this Jenkins pipeline fail with an error during the input step?

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?

Jenkins
stage('Approval') {
  steps {
    input 'Approve deployment?'
    echo 'Deployment approved'
  }
}
AThe input step requires a message parameter with key 'message', not a plain string.
BThe input step requires at least one button label specified with 'ok' parameter.
CThe input step cannot be used inside steps block, it must be in script block.
DThe input step requires a timeout parameter to avoid errors.
Attempts:
2 left
💡 Hint

Check the required parameters for the input step in Jenkins pipeline.

🔀 Workflow
advanced
2:00remaining
What happens to the Jenkins pipeline if the input step times out?

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?

Jenkins
stage('Approval') {
  steps {
    input message: 'Approve?', ok: 'Yes', timeout: 60
    echo 'Approved'
  }
}
AThe pipeline aborts the build with an error.
BThe pipeline continues immediately to the next step without approval.
CThe pipeline retries the input step indefinitely.
DThe pipeline pauses indefinitely until manual intervention.
Attempts:
2 left
💡 Hint

Think about what Jenkins does when a timeout occurs on an input step.

Best Practice
expert
3:00remaining
Which Jenkins pipeline snippet correctly captures user input with multiple options and stores the result?

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?

Adef env = input message: 'Select environment', parameters: [password(name: 'env', defaultValue: 'dev', description: 'Choose environment')]
Bdef env = input message: 'Select environment', parameters: [string(name: 'env', defaultValue: 'dev', description: 'Choose environment')]
Cdef env = input message: 'Select environment', ok: 'Select', parameters: [booleanParam(name: 'env', defaultValue: true, description: 'Choose environment')]
Ddef env = input message: 'Select environment', parameters: [choice(name: 'env', choices: 'dev\nstaging\nprod', description: 'Choose environment')]
Attempts:
2 left
💡 Hint

Which parameter type allows selecting from multiple predefined options?