0

Based on the parameter selected (Eg. choice - in this case), need to scale up/down the pipeline stages.

if(choice.equals("four")){
    pipeline{
       <4 stages>
    }
}else{
    pipeline{
       <3 stages>
    }
}

Is it possible to implement something like this?

1 Answers1

0

You can define a super-set of all the stages and then run only the stages you need, like this:

pipeline {
    agent any
    stages {
        stage('Always') {
            steps {
            ...
            }
        }

        stage('Only when Four') {
            when {
                environment name: 'CHOICE', value: 'four'
                beforeAgent true
            }
            steps {
            ...
            }
        }
    }
}
MaratC
  • 6,418
  • 2
  • 20
  • 27