Ideas or code sources:
https://serverfault.com/questions/915708/jenkins-using-parameterized-trigger-plugin-via-pipeline-script
Heya,
Just a small groovy code snippet to trigger another job with parameters via Jenkins Scripted Pipeline:
build(
job: 'my-job-name',
parameters: [
[
$class: 'StringParameterValue',
name: 'myStringParameter',
value: "my value",
],
[
$class: 'BooleanParameterValue',
name: 'myBooleanParameter',
value: true,
],
// etc.
],
)
And if we might want to run several jobs in parallel then we do following:
node("master") {
List<String> jobNames = [
"test-folder/test-job-1",
"test-folder/test-job-2",
"test-folder/test-job-3",
]
Map jobs = [:]
jobNames.each {
jobName -> jobs["job-${jobName}"] = {
stage("Trigger ${jobName}") {
build(
job: "${jobName}",
wait: true,
propagate: true,
parameters: [
[
$class: 'StringParameterValue',
name: 'SOME_PARAMETER',
value: "SOME_VALUE",
],
],
)
}
}
}
parallel jobs
}
That’s it
Happy pipelining
!