问题
How can you pass same parameters to different builds without redundant code in Jenkins Pipeline groovy. I don't want to repeat the parameters.
node('master') {
parallel(
"stream 1(X)" : {
stage('X') {
build 'Job1', parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')]
}
},
"stream 2 (Y)" : {
stage('Y') {
build 'Job2', parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')]
}
}
)
}
回答1:
It is pretty easy : just add a function, say buildJob
, that will take your job name as a parameter and then set all jobs parameters as you do it now :
node('master') {
parallel(
"stream 1(X)" : {
stage('X') {
buildJob("Job1")
}
},
"stream 2 (Y)" : {
stage('Y') {
buildJob("Job2")
}
}
)
}
def buildJob(jobName) {
build name: jobName, parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')]
}
来源:https://stackoverflow.com/questions/40509430/how-can-you-pass-same-parameters-to-different-builds-without-redundant-code-in-j