DEV Community

Discussion on: Jenkins Pipelines and their dirty secrets 3.

 
cvega profile image
Casey Vega • Edited

Use what is known as a parameterized pipeline. You can set default environment variables for code runs.

when you want to change the behavior of the pipeline stage you can modify the parameter. If you set the toggle parameter to false in the UI, or by calling the build via URL, it will now skip the first stage because it's not true

Calling via URL:
http://server/job/project/buildWithParameters?toggle=false

pipeline {
  agent any
  parameters {
    booleanParam(name: 'toggle', defaultValue: true)
  }
  stages {
    stage('optional stage') {
      when (toggle: true) {
        sh `make clean`
      }
    }
  }
}