Reputation: 1423
I have two Jenkins pipeline (a)deploy
and (b)test_deploy
. I want to run both these pipeline from one Jenkinsfile as there functionality is same.
deploy
pipeline runs on for all non-test environmentstest_deploy
pipeline will run only on test
environmentsI want to only show test environments as parameters in test_deploy
pipeline. I want to add something like if/else conditions on choice parameters that will return environment names in parameters based upon the job name. How can I condition choice/parameters based upon job name?
Upvotes: 1
Views: 495
Reputation: 4203
You can add this at the top of your Jenkinsfile:
if (JOB_NAME == 'deploy') {
properties([
parameters([
choice(name: 'deployEnv', choices: ['deployEnv1', 'deployEnv2'], description: '')
])
])
} else if (JOB_NAME == 'test_deploy') {
properties([
parameters([
choice(name: 'testEnv', choices: ['testEnv1', 'testEnv2'], description: '')
])
])
}
This works in both Declarative and Scripted Pipelines, and populates the choice parameters based on the job names.
Upvotes: 2