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 (created on the Manage Jenkins โ†’ Configure System screen under the Global Properties heading) that contains a space. I want to use this environment variable in the Execute Shell build step. An option that should appear on the command line at the build stage:

--platform="Windows 7" 

The syntax I use on the command line is --platform=${VARIABLE_NAME}

No matter how I try to format it, Jenkins seems to reformat it so that it is treated as two values. I tried:

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

Corresponding results when the output at the execution stage of the Execute Shell assembly was as follows:

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

I also tried changing the command line syntax to --platform='${VARIABLE_NAME}' , as well as '--platform=${VARIABLE_NAME}' , but in each of these cases ${VARIABLE_NAME} is not allowed at all and just appears as ${VARIABLE_NAME} in the received team.

I hope there is a way to make this work. Any suggestions are most appreciated.

+8
environment-variables jenkins
source share
1 answer

You should be able to use spaces without any special characters in the global properties section.

For example, I set the variable "THIS_VAL" to the value "HAS SPACES".

My task of building the test was as follows:

 #!/bin/bash set +v echo ${THIS_VAL} echo "${THIS_VAL}" echo $THIS_VAL 

and there was a way out

 [workspace] $ /bin/bash /tmp/hudson8126983335734936805.sh HAS SPACES HAS SPACES HAS SPACES Finished: SUCCESS 

I think you need to do the following:

 --platform="${VARIABLE_NAME}" 

NOTE. Use double quotes, not single quotes . The use of single quotes makes the material inside the quotes literal, which means that any variables will be printed as is, and not analyzed in the actual value. Therefore, '$ {VARIABLE_NAME}' will be printed as is, not parsed in Windows 7.


EDIT: Based on @BobSilverberg's comment below, use the following:

 --platform="$VARIABLE_NAME" 

Note: no curly braces.

+6
source share

All Articles