To prevent production change in controllable manner, some organization require to have some manual approval in the process. To Implement in Jenkins, either use pipeline command or script.In this demo, it will set the boolean to mark user approve to deploy.
stage('Publish') { steps { script { if(env.BRANCH_NAME=='master') { def isContinue=input( message: "Continue deploy to Production Environment?", parameters: [ [$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Checked means you acknowledge and approve with this deployment'] ]) echo "isContinue=${isContinue}" if(isContinue) { echo "deploy continue" } else { currentBuild.result = 'FAILURE' echo "User untick and not agree on it." } } else { echo "no need to approve" } } } }
For parameters, there are variants options but I use simple one as demo. Details can refer to reference (1).
Also, for currentBuild.result, there are 3 status: SUCCESS, FAILURE and UNSTABLE, unstable mean it has problem during execute but still success.
Reference
- Pipeline: Input Step, Jenkins,
https://www.jenkins.io/doc/pipeline/steps/pipeline-input-step/
Leave a Reply