Pipeline: Defined parameters are not available in the build

1,277 views
Skip to first unread message

Sverre Moe

unread,
Jun 22, 2016, 7:13:48 AM6/22/16
to Jenkins Users
Have defined parameter for my pipeline projects in the main pipeline script:
properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Description', name: 'PROP_VERIFY']]]])

After building the first time with this I get the option "Build with Parameters".

Doesn't matter how I start a new build. Either manually or in the script:
build job: '../projectA/master', parameters: [[$class: 'BooleanParameterValue', name: 'PROP_VERIFY', value: true]]
The environment variable env.PROP_VERIFY is not available. It it always null.

After building I am checking the following URL and can se that the parameter is set:

Sverre Moe

unread,
Jun 22, 2016, 7:19:28 AM6/22/16
to Jenkins Users
Seems there is an issue for this

I hope for a fix soon. I am stuck without this.

Björn Pedersen

unread,
Jun 22, 2016, 7:31:01 AM6/22/16
to Jenkins Users
Is '../projectA/master' configured to accept parameter PROP_VERIFY (In the job definition, not in the Jenkinsfile)? Else I guess due to SEC-170 fixes, the parameter is not propagetd to the environment. Actually that would be a chicken-and-egg type problem. You need to get and execute the current jenkinsfile to see, if the param is allowed, but the param should already be set. See https://jenkins.io/blog/2016/05/11/security-update/ for details.

The linked issue seem to be a slightly different problem.

Björn

Sverre Moe

unread,
Jun 22, 2016, 7:37:29 AM6/22/16
to Jenkins Users
Yes it is in the job configuration for the multibranch pipeline job

Running the following in the script (Jenkinsfile) should add the parameter to the branch projects configuration.
properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'BooleanParameterDefinition',defaultValue: false, description: 'Description', name: 'PROP_VERIFY']]]])
The next time building "Build with parameter" you can check this parameter, but it is not available in the build.

After SECURITY-170 all parameters not defined in the project was no longer available. Triggering a downstream build with a parameter not defined was not propagated to the downstream build. After adding the parameter it gets propagated.

Sverre Moe

unread,
Jun 23, 2016, 3:55:51 AM6/23/16
to Jenkins Users
It is working. I was just accessing the parameter in a wrong way.
Trying env.PARAM does not work.
Found an example that lead me to the answer.
def param = false
if (getBinding().hasVariable("MY_PARAM")) {
    param
= MY_PARAM
}

Reply all
Reply to author
Forward
0 new messages