4

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?

2

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]}"

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.