Is there a way to insert a manual approval in Jenkins 2 pipelines?

Solution 1:

input is the option you are looking for. Here is the way I'm using it. It's important to have the step outside a node, otherwise jenkins will hold an agent waiting for the next step. Keep in mind the second node may not use the same workspace as the first.

node {
    stage('build'){
        echo "building"
    }
}
stage('Deploy approval'){
    input "Deploy to prod?"
}
node {
    stage('deploy to prod'){
        echo "deploying"
    }
}

Solution 2:

I did in as shown below way by reading this docs https://jenkins.io/doc/book/pipeline/syntax/

pipeline {
environment {
    BRANCH_NAME = "${env.BRANCH_NAME}"
}
agent any
stages{
    stage('Build-Initiator-Info'){
            steps{
                sh 'echo "Send Info"'
            }
    }
    stage('Build') {
        steps{
             catchError {
                sh 'echo "This is build"'
            }
         }
         post {
            success {
                echo 'Compile Stage Successful . . .'
            }
            failure {
                echo 'Compile stage failed'
                error('Stopping early…')

             }
    }
   }
  stage ('Deploy To Prod'){
  input{
    message "Do you want to proceed for production deployment?"
  }
    steps {
                sh 'echo "Deploy into Prod"'

              }
        }
  }
   }