Approval process in pipeline

Jenkins Pipeline is a suite of plugins that supports implementing and integrating continuous delivery pipelines into Jenkins. A continuous delivery pipeline is an automated expression of our process for getting software from version control right through to our users and customers

we need to promote our build to production using Jenkins file only if it is approved by change management using ServiceNow change ticket or by manual approval. I want something like: - Prod build can only be triggered manually if it is approved by the manager(he/she should receive the approval mail with the link to approve/reject) or - if the ServiceNow change ticket associated with the change is approved by all the approvers, if (changeticket== "APPROVED") then you can trigger the build deployment in production
My Jenkinsfile would look something like this
stages {
  stage('Checkout') {
  steps {
  git credentialsId: 'userId', url: 
  'https://github.com/NeelBhatt/SampleCliApp', branch: 'master'
     }
         }
   stage('Restore PACKAGES') {
   steps {
    bat "dotnet restore --configfile NuGet.Config"
         }
                              }
   stage('Clean') {
   steps {
   bat 'dotnet clean'
         }
                  }
   stage('Build') {
   steps {
   bat 'dotnet build --configuration Release'
         }
                 }
   stage('Pack') {
   steps {
   bat 'dotnet pack --no-build --output nupkgs'
         }
                 }
   stage('Publish') {
   steps {
   bat "dotnet nuget push **\\nupkgs\\*.nupkg -k yourApiKey -s            
   http://myserver/artifactory/api/nuget/nuget-internal-stable/com/sample"
         }
                    }
      }
      }

we need to add an INPUT step in our Pipeline to ask for user input and take action on the result. In our case, we can add an email step to send an email link to this Pipeline that will ask for approval. And the Deployment step will take action after the Input step has been approved
stage("Stage with input") {
    steps {
      def userInput = false
        script {
            def userInput = input(id: 'Proceed1', message: 'Promote build?', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this']])
            echo 'userInput: ' + userInput

            if(userInput == true) {
                // do action
            } else {
                // not do action
                echo "Action was aborted."
            }

        }    
    }  
}
Optionally: we can surround this with a timeout so it won't wait forever.
There are a few different ways to send an email, but this is one of them:
// send to email
emailext (
  subject: "Waiting for your Approval! Job: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
  body: """

STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':

             

Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"

""",
  recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)




Recent Comments

No comments

Leave a Comment