bash 如何在shell脚本中使用Jenkins环境变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21034043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Jenkins environment variable in shell script?
提问by Graeme
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:
我想用 jenkins 内部版本号更新一个 java 文件。我计划使用 shell 脚本将值发送到正确的内部版本号。我目前正在这样做:
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.
为什么这不起作用?我假设我可以直接使用它们。
回答by that other guy
As shellcheckwould tell you, expansions don't happen in single quotes. Use double quotes instead:
正如shellcheck会告诉您的那样,扩展不会发生在单引号中。改用双引号:
sed -i "s/Version 3.0/Version $BUILD_DISPLAY_NAME/g" /var/lib/jenkins/jobs/AndroidTest/workspace/xxx/res/values/strings.xml