7

Google has failed to even lead me to a proper answer as to why spaces are permitted in names of Jenkins parameters, let alone how to reference them. Assuming it's not just a major oversight, how does one access these parameters?

For example, I have a string parameter named "IP Address". I could rename it "IP_Address" but I'm trying to avoid the underscores_as_spaces if I can.

I've tried to refer to this parameter using "${IP Address}", "IP Address" and even "IP\ Address" but nothing seems to work. Is there any way to actually reference these?

5

You can use params['IP Address'].

Think of params as a Map containing a key 'IP Address'. If the key didn't have a space, then you could use params.IPAddress or params['IPAddress'], but when there's a space, you can only use the latter syntax.

That syntax is also useful when you're computing the key name to look up, and have stored it in a variable:

final String myParam = "param${i}"
// can't say `params.myParam`
echo "Value is ${params[myParam]}"
1
  • This doesn't work for me. In my declarative pipeline (Jenkinsfile) I've tried to do a when clause like this: when { expression { params['Force generate NuGet'] == "true" } }, but when I run my job and provide a parameter value, it doesn't pick up the value I gave it. Are there any pitfalls I should be aware of, any things I might be doing wrong? – Claus Appel Feb 9 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.