Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (50.2k points)

I am studying the capabilities of Jenkins Pipeline: Multibranch. It is said that a recently introduced properties step might be useful there, but I can't catch how it works and what is its purpose.

Its hint message doesn't seem to be very clear:

Updates the properties of the job which runs this step. Mainly useful from multibranch workflows, so that Jenkinsfile itself can encode what would otherwise be static job configuration.

So I created a new Pipeline with this as a script (pasted directly into Jenkins not in SCM):

properties [[$class: 'ParametersDefinitionProperty',

   parameterDefinitions: [[$class: 'StringParameterDefinition',

       defaultValue: '', description: '', name: 'PARAM1']]

]]

I ran it and nothing happened, the job didn't receive a new parameter and even if it did I don't get why I might need this. Could anyone please explain?

I tried putting a dummy Pipeline with properties step into my git repo, then configured a multibranch job.

println 1

properties [[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'StringParameterDefinition', defaultValue: 'str1', description: '', name: 'PARAM1']]], [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false]]

println 2

It found my branch, created a job but the build failed with:

when I put the same script (as in UPD1) back into Jenkins and runs it, it asked for new permission method groovy.lang.GroovyObject getProperty java.lang.String. I approved it, the build went green, however, no changes to the job configuration appeared.

My env is: Jenkins 1.625.3, Pipeline+Multibranch 1.13

1 Answer

0 votes
by (29.3k points)

You can resolve this issue by Using properties with explicit method syntax will work,

i.e.: properties( [ ... ] ) rather than properties [ ... ]

Alternatively, it will work without if you specify the parameter name, 

e.g.:properties properties: [ ... ]

If you wish, you can learn more about Jenkins by visiting Jenkins Tutorial and join Jenkins Certification.

Browse Categories

...