Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Jenkins environment variable in shell script?

Tags:

bash

jenkins

I want to update a java file with the jenkins build number. I plan on using a shell script to sed the value to the correct build number. I'm currently doing this:

sed -i 's/Version 3.0/Version $BUILD_DISPLAY_NAME/g'
/var/lib/jenkins/jobs/AndroidTest/workspace/xxx/res/values/strings.xml

Why doesn't this work? I'd assume I could just use them directly.

like image 866
Graeme Avatar asked Jan 10 '14 00:01

Graeme


People also ask

How do I pass an environment variable in bash script?

The easiest way to set environment variables in Bash is to use the “export” keyword followed by the variable name, an equal sign and the value to be assigned to the environment variable.

How do I set an environment variable in shell?

You can set your own variables at the command line per session, or make them permanent by placing them into the ~/. bashrc file, ~/. profile , or whichever startup file you use for your default shell. On the command line, enter your environment variable and its value as you did earlier when changing the PATH variable.


1 Answers

As shellcheck would tell you, expansions don't happen in single quotes. Use double quotes instead:

sed -i "s/Version 3.0/Version $BUILD_DISPLAY_NAME/g" /var/lib/jenkins/jobs/AndroidTest/workspace/xxx/res/values/strings.xml
like image 108
that other guy Avatar answered Nov 11 '22 02:11

that other guy