Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a value for a Jenkins environment variable that contains a space

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:

  • Windows 7
  • "Windows 7"
  • 'Windows 7'
  • Windows\ 7

The corresponding results, when output during the Execute Shell build step have been:

  • --platform=Windows 7
  • '--platform="Windows' '7"'
  • '--platform='\''Windows' '7'\'''
  • --platform=Windows/ 7

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.

like image 915
BobSilverberg Avatar asked Jul 10 '13 14:07

BobSilverberg


People also ask

How do I find the value of an environment variable?

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.

How can you modify PATH variable in Jenkins master?

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.


1 Answers

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.

like image 178
Sagar Avatar answered Sep 28 '22 01:09

Sagar