1

While I am aware of this question clean way to exit declarative Jenkins pipeline as success I am to green to understand how to put it to use (from where does the skipBuild variable come?).

I have a script that determines whether the pipeline should continue or not but I am unsure how to piece it together (I am free to construct the script as needed).

pipeline { 
    agent {
        docker { image 'python:3-alpine' }
    }

    stage('Should I continue') {
        steps {
            python should_i_continue.py
        }
        when { ? == true } 
        stages {
           ...
        }
    }
}

I am aware that the capabilities increase tenfold if I use a scripted pipeline but I wonder if it is possible to do what I want with a declarative one?

Hampus
  • 2,769
  • 1
  • 22
  • 38

1 Answers1

0

You can use any custom variable, which you will set as true|false based on some condition in the steps of your pipeline and all stages that need to be executed based on that condition have to have following format:

stage('Should Continue?') {
   setBuildStatus("Build complete", "SUCCESS");
   when {
     expression {skipBuild == true }
   }
}

In other words to provide you a bit clean picture, check this abstract example:

node {
  skipBuild = false

  stage('Checkout') {
    ...
    your checkout code here
    ...
  }

  stage('Build something') {
    ...
    some code goes here
    skipBuild = true
    ...
  }

  stage('Should Continue?') {
    setBuildStatus("Build complete", "SUCCESS");
    when {
       expression {skipBuild == true }
    }
  }
}
BigGinDaHouse
  • 1,282
  • 9
  • 19
  • The question is specifically how in can be solved using a __declarative__ pipeline. As I said I know that the capabilities of what you can do increase tenfold if I use a scripted. – Hampus Jan 14 '19 at 08:39