0

I would like to pre-populate Jenkins Parameter with a Build Variable using the Dynamic Parameter Plug-In.

I added a Groovy script under the Scriptler section of Jenkins:

return $JOB_NAME

JOB_NAME is Jenkins Environment Variable obtained from: ~/env-vars.html

And then added a "Dynamic Parameter (Scriptler)" as below:

enter image description here

However when clicking "Build with Parameters" I don't see the value populated.

I'm totally new to this and not sure if this is the right way to achieve it. Thanks in advance for the help.

1 Answers1

0

Try

return "\$JOB_NAME"

NOTE: It's not sufficient to merely return the string "$JOB_NAME", because Groovy interpolates strings. It seems the script runs in an environment where specific build parameters are not available. By escaping the dollar sign, the string gets passed 1:1 to the dynamic parameter.

If you just want to inject the build- and/or job specific parameters, a text parameter defaulting to $JOB_NAME seems to work also.

Community
  • 1
  • 1
Stefan Hanke
  • 3,458
  • 2
  • 30
  • 34
  • Escaping "$" didn't work. Also tried defaulting to $JOB_NAME. But it just prints $JOB_NAME and not value. – user1349736 Aug 19 '16 at 08:24
  • @user1349736: `Job Name` - if this is the parameter's name, perhaps there's a problem with it having a space. See e.g. [here](http://stackoverflow.com/questions/18468397/how-can-you-access-an-environment-variable-that-has-a-space-in-its-name-in-bash). – Stefan Hanke Aug 19 '16 at 15:44