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 SportIndia.in

Configuring Jenkins Pipeline With Checkpoint
10 May 2017

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
node {
    stage('Build') {
      checkout scm
      ...
    }

    stage('Test') {
      echo 'Running tests'
      ...
      milestone()
    }

    stage('Confirm Deployment') {
      echo 'Getting confirmation for deployment'
    }
}

input "Deploy to QA box?"

node {
  stage('Deploy to QA') {
    milestone()
    lock('QADeploy') {
      #Scripts for deployment#
    }
  }
}

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