[Jenkins] How to pass choice parameter in Jenkins file
Recentally I was working in converting our pipeline jenkin jobs to Jenkinsfiles so that it can be better managed and tracked. In the jenkin file, I was using declarative pipeline.
In one of the jenkin file, I have to pass the choice parameters from one job to another.
To implement this, I first created the choice parameter in jenkin file as:
properties([
paramteres([
choice(choices:['https://www.google.com', 'https://s-www.google.com', 'https://d-www.google.com'], description: 'Select your env?', name:'url')
])
])
Then I stored the url value inside a variable:
def env = params.url
After getting the env, we can pass it in the job as :
pipeline {
agenet none{
stages('') {
parallel {
stage('Run your first job') {
steps {
script {
build(job: 'Job path' , paramters:[string(name:'url', value:String.valueof(params.url))])
}
}
}
stage('Run your second job') {
......................
}
}
} // close stages
post {
always {
}
}
This allows to pass the chocie aprameter from parent job to downstream jobs.