2

I have a Jenkins pipeline where I trigger a single job with different parameters. The number of parameters may also change which changes the number of times the job needs to be triggered. This is why I have the build job in a for loop. Here's what the code looks like:

pipeline{

    stages{
        stage('Setup'){
            steps{
                script {
                    for (int i=0; i<list_one.size(); i++ ) {
                    def index_i = i
                        for (int j=0; j<list_two.size(); j++) {
                            def index_j = j
                            stage ("${list_one[i]} ${list_two[j]}") {
                                sh "echo 'index_i: ${index_i}'"
                                sh "echo 'index_j: ${index_j}'"
                                build job: 'Downstream Job', parameters: [
                                    string(name: 'some_param', value: "${list_one[index_i]}")]
                            }
                        }
                    }
                }
            }
        }
    }
}

When I run this pipeline, it only runs once for the first iteration of both the loops. However when I remove the build job line, the pipeline runs for all the values in the list. I'm perplexed by why this would be and would like some assistance in the matter.

Shubham Vasaikar
  • 698
  • 9
  • 23
  • 1
    hmm is the Job triggered for the first time is passing? if not then it will mark the job as failure and abort rest of the iterations. – vipin yadav May 11 '21 at 08:39
  • I think there should be a parallel statement. – Holleoman May 12 '21 at 19:15
  • No I specifically wanted these jobs to run sequentially, not in parallel. Also, to use `parallel` I think you need to create a map of closures first that includes all these `build job` statements, then pass that to the `parallel`. – Shubham Vasaikar May 13 '21 at 09:59

1 Answers1

1

Or you can use something like propagate=false.

Is there a way to use "propagate=false" in a Jenkinsfile with declarative syntax directly for stage/step?

vipin yadav
  • 74
  • 2
  • 10