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

Pipeline build parameters are null in first build

    Details

    • Similar Issues:

      Description

      Parameters which are set in properties in a pipeline build are null the first time the build is run, even if they are given default values. On subsequent builds, the parameters have values as expected.

      Example: create a new Pipeline job and define the pipeline script like this in the build config:

      properties([
        [$class: 'ParametersDefinitionProperty',
          parameterDefinitions: [
            [$class: 'StringParameterDefinition',
              name: 'SOME_PARAMETER',
              defaultValue: 'some value',
              description: 'A test parameter']]
        ]
      ])
      
      echo "Value of parameter:"
      echo env.SOME_PARAMETER
      

      Run the build by clicking "Build" (note that this says "Build" rather than "Build with Parameters" unless the build has been run at least once). The console output is:

      [Pipeline] echo
      Value of parameter:
      [Pipeline] echo
      null
      

      Run the build a second time by clicking "Build with Parameters" and then confirming the default value. The console output is now:

      [Pipeline] echo
      Value of parameter:
      [Pipeline] echo
      some value
      

      If you refer to the parameter directly using SOME_PARAMETER rather than env.SOME_PARAMETER, the first build fails with a groovy.lang.MissingPropertyException instead.

      This isn't so bad when you're configuring a single new job, but it becomes a real problem for multibranch pipeline jobs, because the first build of every branch always fails unless the pipeline script does extra work to handle the missing parameter.

        Attachments

          Issue Links

            Activity

            suzannehamilton Suzanne Hamilton created issue -
            suzannehamilton Suzanne Hamilton made changes -
            Field Original Value New Value
            Description Parameters which are set in {{properties}} in a pipeline build are null the first time the build is run, even if they are given default values. On subsequent builds, the parameters have values as expected.

            Example: create a new Pipeline job and define the pipeline script like this in the build config:

            {code}
            properties([
              [$class: 'ParametersDefinitionProperty',
                parameterDefinitions: [
                  [$class: 'StringParameterDefinition',
                    name: 'SOME_PARAMETER',
                    defaultValue: 'some value',
                    description: 'A test parameter']]
              ]
            ])

            echo "Value of parameter:"
            echo env.SOME_PARAMETER
            {code}

            Run the build by clicking "Build" (note that this says "Build" rather than "Build with Parameters"). The console output is:

            {code}
            [Pipeline] echo
            Value of parameter:
            [Pipeline] echo
            null
            {code}

            Run the build a second time by clicking "Build with Parameters" and then confirming the default value. The console output is now:

            {code}
            [Pipeline] echo
            Value of parameter:
            [Pipeline] echo
            some value
            {code}

            If you refer to the parameter directly using {{SOME_PARAMETER}} rather than {{env.SOME_PARAMETER}}, the first build fails with a {{groovy.lang.MissingPropertyException}} instead.

            This isn't so bad when you're configuring a single new job, but it becomes a real problem for multibranch pipeline jobs, because the first build of every branch always fails unless the pipeline script does extra work to handle the missing parameter.
            Parameters which are set in {{properties}} in a pipeline build are null the first time the build is run, even if they are given default values. On subsequent builds, the parameters have values as expected.

            Example: create a new Pipeline job and define the pipeline script like this in the build config:

            {code}
            properties([
              [$class: 'ParametersDefinitionProperty',
                parameterDefinitions: [
                  [$class: 'StringParameterDefinition',
                    name: 'SOME_PARAMETER',
                    defaultValue: 'some value',
                    description: 'A test parameter']]
              ]
            ])

            echo "Value of parameter:"
            echo env.SOME_PARAMETER
            {code}

            Run the build by clicking "Build" (note that this says "Build" rather than "Build with Parameters" unless the build has been run at least once). The console output is:

            {code}
            [Pipeline] echo
            Value of parameter:
            [Pipeline] echo
            null
            {code}

            Run the build a second time by clicking "Build with Parameters" and then confirming the default value. The console output is now:

            {code}
            [Pipeline] echo
            Value of parameter:
            [Pipeline] echo
            some value
            {code}

            If you refer to the parameter directly using {{SOME_PARAMETER}} rather than {{env.SOME_PARAMETER}}, the first build fails with a {{groovy.lang.MissingPropertyException}} instead.

            This isn't so bad when you're configuring a single new job, but it becomes a real problem for multibranch pipeline jobs, because the first build of every branch always fails unless the pipeline script does extra work to handle the missing parameter.
            glib_briia Glib Briia made changes -
            Priority Minor [ 4 ] Major [ 3 ]
            sdfnanderson anderson oliveria made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            sdfnanderson anderson oliveria made changes -
            Labels Parameters Pipeline
            sdfnanderson anderson oliveria made changes -
            Labels Parameters Pipeline Build Jenkinsfile Parameters Pipeline
            childnode Marcel 'childNo͡.de' Trautwein made changes -
            Link This issue is duplicated by JENKINS-42922 [ JENKINS-42922 ]
            childnode Marcel 'childNo͡.de' Trautwein made changes -
            Link This issue is duplicated by JENKINS-41929 [ JENKINS-41929 ]
            abayer Andrew Bayer made changes -
            Link This issue duplicates JENKINS-41929 [ JENKINS-41929 ]
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] Resolved [ 5 ]
            Resolution Duplicate [ 3 ]
            slonopotamusorama Marat Radchenko made changes -
            Link This issue is duplicated by JENKINS-41929 [ JENKINS-41929 ]

              People

              • Assignee:
                Unassigned
                Reporter:
                suzannehamilton Suzanne Hamilton
              • Votes:
                9 Vote for this issue
                Watchers:
                15 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: