I have a pipeline job which run some sequence of action (Eg; Build >> Run >> Report). I ahave put this sequence in a for loop as I can get a parameter how many times I should repeat the same sequence. Please find the sample code I have written.
for (int i = 0; i < <param_val>; ++i){
node{
stage('Build') {
build 'Build'
}
stage('Run') {
build 'Run'
}
stage('Reporting') {
build 'Reporting'
}
}
}
Now my code is waiting for one complete sequence to happen and then continue to run the next sequence. That is time consuming. I have more slave agents and can run the sequence in parallel. How can I run each iteration of a for loop parallel?
I have thought of a solution : have a pipeline having the actual sequence
node{
stage('Build') {
build 'Build'
}
stage('Run') {
build 'Run'
}
stage('Reporting') {
build 'Reporting'
}
}
have another pipeline with the for loop which will trigger the 1st pipeline with wait: false:
for (int i = 0; i < <param_val>; ++i){
build(job: 'pipeline-1', wait: false)
}
Does this work ? Or do we have a better option to do the same with single pipeline ?