How to use if statement between parameters in Jenkinsfile

27 views Asked by At

Is there any possibility to use an if statement between parameters in Jenkinsfile something like below :

I used Active Choice plugin so I am not looking for that solution

properties([
        parameters([
            choice(
                name: 'option1',
                choices: [ "1", "2" ]
            ),              
            if (option1.equal("1"){
                choice(
                    name: 'option2',
                    choices: [ "3", "4" ]
                )
            }
        ])
])
1

There are 1 answers

0
Alexander Pletnev On BEST ANSWER

I used Active Choice plugin so I am not looking for that solution

Apart from impossibility to use conditions mentioned by Noah Helmer in the comments, there is no way to do that without the external plugins because of the Jenkins architecture - it does not evaluate the Jenkinsfile before running the build.

All that you can see in Jenkins UI when you click the Build with parameters button is the result of the previous build that loaded the previous version of your Jenkinsfile. It will still apply even if you use Active Choices or another plugin.