I am trying to specify a value for a Jenkins environment variable (as created on the Manage Jenkins -> Configure System screen, under the heading "Global properties") which contains a space. I want to use this environment variable in an Execute Shell build step. The option that I need to appear in the command line in the build step is:
--platform="Windows 7"
The syntax I am using on the command line is --platform=${VARIABLE_NAME}
No matter how I attempt to format it, Jenkins seems to reformat it so that it is treated as two values. I have tried:
The corresponding results, when output during the Execute Shell build step have been:
I have also tried changing my command line syntax to --platform='${VARIABLE_NAME}'
as well as '--platform=${VARIABLE_NAME}'
, but in each of those cases the ${VARIABLE_NAME}
is not resolved at all and just appears as ${VARIABLE_NAME}
on the resulting command.
I am hoping there is a way to make this work. Any suggestions are most appreciated.
To display the values of environment variables, use the printenv command. If you specify the Name parameter, the system only prints the value associated with the variable you requested.
From "Global Properties -> Environment Variables" i add 2 entries: "PATH" with value "$PATH:/opt/foo" and "FOO" with value "BAR". Now when i run my free style job with execute shell build step being "echo $PATH; echo $FOO" i see that PATH was not modified whereby FOO is displayed correctly.
You should be able to use spaces without any special characters in the global properties section.
For example, I set a variable "THIS_VAL" to have the value "HAS SPACES".
My test build job was the following:
#!/bin/bash
set +v
echo ${THIS_VAL}
echo "${THIS_VAL}"
echo $THIS_VAL
and the output was
[workspace] $ /bin/bash /tmp/hudson8126983335734936805.sh
HAS SPACES
HAS SPACES
HAS SPACES
Finished: SUCCESS
I think what you need to do is use the following:
--platform="${VARIABLE_NAME}"
NOTE: Use double quotes, not single quotes. Using single quotes makes the stuff inside the quotes literal, meaning that any variables will be printed as is, not parsed into the actual value. Therefore '${VARIABLE_NAME}' will be printed as is, not parsed into "Windows 7".
EDIT: Based on @BobSilverberg comment below, use the following:
--platform="$VARIABLE_NAME"
Note: no curly brackets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With