[JIRA] (JENKINS-40574) Pipeline build parameters are null in first build

3 views
Skip to first unread message

suzanne.m.hamilton@gmail.com (JIRA)

unread,
Dec 20, 2016, 11:07:01 AM12/20/16
to jenkinsc...@googlegroups.com
Suzanne Hamilton created an issue
 
Jenkins / Bug JENKINS-40574
Pipeline build parameters are null in first build
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline
Created: 2016/Dec/20 4:06 PM
Priority: Minor Minor
Reporter: Suzanne Hamilton

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"). 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.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

suzanne.m.hamilton@gmail.com (JIRA)

unread,
Dec 20, 2016, 11:07:01 AM12/20/16
to jenkinsc...@googlegroups.com
Suzanne Hamilton updated an issue
Change By: Suzanne Hamilton
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.

suzanne.m.hamilton@gmail.com (JIRA)

unread,
Dec 20, 2016, 11:09:01 AM12/20/16
to jenkinsc...@googlegroups.com

letangp@gmail.com (JIRA)

unread,
Mar 6, 2017, 4:41:02 PM3/6/17
to jenkinsc...@googlegroups.com

You can get around this by using params.SOME_PARAMETER instead of env.SOME_PARAMETER.

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

zach.mcauliffe@gmail.com (JIRA)

unread,
Jul 24, 2019, 6:41:03 PM7/24/19
to jenkinsc...@googlegroups.com
M P edited a comment on Bug JENKINS-40574
The workaround that we're currently using is to just simply map all parameters to environment variables after the parameters block explicitly:
{code:java}
properties([
    parameters([
        string(name: "FOO", defaultValue: "bar"),
    ])
])
params.each { k, v -> env[k] = v }

echo "FOO=${env.FOO}"{code}
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

zach.mcauliffe@gmail.com (JIRA)

unread,
Jul 24, 2019, 6:41:03 PM7/24/19
to jenkinsc...@googlegroups.com
M P commented on Bug JENKINS-40574

The workaround that we're currently using is to just simply map all parameters to environment variables after the parameters block explicitly:

properties([
    parameters([
        string(name: "FOO", defaultValue: "bar"),
    ])
])
params.each { k, v -> env[k] = v }

echo "FOO=${env.FOO}"
Add Comment Add Comment
 
Reply all
Reply to author
Forward
0 new messages