Sudhakar Rayavaram
Problem solver (And maker),
Inquisitive (Root to most of my problems),
Software craftsman (Don't ask for estimates)

Works at TarkaLabs

Tech guy behind

10 May 2017
Configuring Jenkins Pipeline With Checkpoint

Jenkins community created a plugin called Blue Ocean that overhauled the user experience of Jenkins. And, It is awesome. The UI looks clean, simple and visualizing the pipelines makes it easier to understand what is happening in case of any failure. But, it is not complete

Let us take this simple pipeline. I don't want all the successful builds deployed to QA automatically. Someone should manually promote them. There is no out-of-the-box way to do this in Jenkins community version. A plugin called milestone should be used in tandem with input prompt as shown below

 1 node {
 2     stage('Build') {
 3       checkout scm
 4       ...
 5     }
 7     stage('Test') {
 8       echo 'Running tests'
 9       ...
10       milestone()
11     }
13     stage('Confirm Deployment') {
14       echo 'Getting confirmation for deployment'
15     }
16 }
18 input "Deploy to QA box?"
20 node {
21   stage('Deploy to QA') {
22     milestone()
23     lock('QADeploy') {
24       #Scripts for deployment#
25     }
26   }
27 }
milestone() method is called first in 'Test' stage and then in the 'Deploy to QA' stage. If you notice, the call to get user confirmation (input command) is between the two. This way, whichever run that reaches the second milestone will continue and thus, terminating the other runs

Note: You should not have the 'input' command inside the 'node' block. Or otherwise, the jenkins worker process will be locked till user intervenes