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