0
0
Jenkinsdevops~5 mins

Input step for manual approval in Jenkins - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes, automated pipelines need a human to check and approve before continuing. The input step in Jenkins pauses the pipeline and waits for someone to approve or reject it. This helps avoid mistakes and ensures important decisions are reviewed.
When you want a team lead to approve deployment to production.
When a security check requires manual confirmation before continuing.
When a pipeline needs a manual check after automated tests pass.
When you want to pause a pipeline to review logs or results before next steps.
When compliance rules require human approval before sensitive actions.
Config File - Jenkinsfile
Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building the project...'
      }
    }
    stage('Approval') {
      steps {
        script {
          def userInput = input(
            id: 'userInput', message: 'Approve deployment?', parameters: [
              [$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Check to approve', name: 'Approve']
            ]
          )
          if (!userInput) {
            error('Deployment not approved')
          }
        }
      }
    }
    stage('Deploy') {
      steps {
        echo 'Deploying the project...'
      }
    }
  }
}

This Jenkinsfile defines a pipeline with three stages: Build, Approval, and Deploy.

The Approval stage uses the input step to pause the pipeline and ask for manual approval with a checkbox.

If the checkbox is not checked, the pipeline stops with an error.

If approved, the pipeline continues to the Deploy stage.

Commands
This command updates the Jenkins pipeline job with the Jenkinsfile that includes the input step for manual approval.
Terminal
jenkins-jobs --conf jenkins.ini update Jenkinsfile
Expected OutputExpected
Job updated successfully
Starts the Jenkins pipeline job named 'my-pipeline' and waits for it to complete. The pipeline will pause at the input step waiting for manual approval.
Terminal
jenkins-cli build my-pipeline -s
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] stage [Pipeline] { (Build) Building the project... [Pipeline] } [Pipeline] stage [Pipeline] { (Approval) Waiting for input: Approve deployment?
-s - Waits for the job to complete before returning.
Approves the input step named 'userInput' in the 'my-pipeline' job, allowing the pipeline to continue to the Deploy stage.
Terminal
jenkins-cli input my-pipeline userInput --proceed
Expected OutputExpected
Input approved, continuing pipeline
Shows the console output of the 'my-pipeline' job to verify that the Deploy stage ran after approval.
Terminal
jenkins-cli console my-pipeline
Expected OutputExpected
[Pipeline] stage [Pipeline] { (Deploy) Deploying the project... [Pipeline] } [Pipeline] End of Pipeline Finished: SUCCESS
Key Concept

If you remember nothing else from this pattern, remember: the input step pauses the pipeline and waits for a human to approve before continuing.

Common Mistakes
Not handling the case when approval is denied in the Jenkinsfile.
The pipeline will continue even if the user does not approve, causing unintended deployments.
Use an if statement to check the input result and call error() to stop the pipeline if not approved.
Using input step outside a stage block in the Jenkinsfile.
Jenkins pipelines require steps to be inside stages; otherwise, the pipeline may fail to run.
Always place the input step inside a stage's steps block.
Not specifying an id for the input step and trying to approve via CLI.
Without an id, the CLI cannot identify which input to approve, causing errors.
Always provide an id parameter in the input step to reference it in CLI commands.
Summary
Define an input step inside a stage in Jenkinsfile to pause the pipeline for manual approval.
Use the Jenkins CLI to start the pipeline and approve the input step to continue.
Check the pipeline console output to confirm the deployment stage runs after approval.