Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60511

parameterized project triggered with empty parameters from pipeline's for loop

XMLWordPrintable

      Scenario

      I have two pipeline jobs 'Parent' and 'Child' where 'Child' is parameterized and triggered (fire+forget) from 'Parent' multiple times. The total amount of 'Child' jobs triggered from 'Parent' are variable and depend on external parameters.

       

      // Parent.jenkinsfile
      pipeline {
        agent any
        stages {
          stage('Trigger Child') {
            steps {
              script {
                for(int i = 0; i < 3; ++i) {
                  build(
                    job: 'Child',
                    parameters: [
                      string(name: 'alpha', value: 'test'),
                      string(name: 'beta', value: "${i}")
                    ],
                    wait: false,
                    propagate: false)
                }
              }
            }
          }
        }
      }
      
      // Child.jenkinsfile
      pipeline {
        agent any
        parameters {
          string(name: 'alpha', description: '', trim: true)
          string(name: 'beta', description: '', trim: true)
        }
        stages {
          stage('Hello') {
            steps {
              buildName "${params.alpha} ${params.beta}"
            }
          }
        }
      }
      

      Observed Behaviour

      From any run of 'Parent', 'Child' is getting triggered for each set of parameter values AND one additional time with all parameters set to empty values (or their defaults).

      In the example above, 'Child' is triggered with the following values:

      1. alpha="", beta="null"  <-- should not be there
      2. alpha="test", beta="0"
      3. alpha="test", beta="1"
      4. alpha="test", beta="2"

      Import Note

      This spurious job without parameter values is not being triggered when 'Parent' waits for the 'Child' to finish, i.e. if I set wait=true in the build step of 'Parent'.

       

            Unassigned Unassigned
            tklatt T K
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: