[英]Jenkins shell script does not receive the new value of a job parameter
I'm observing strange unexpected behavior and want your advice, whether it's a bug in Jenkins/Jenkins plugin, or I'm missing the point and should use Jenkins differently. 无论是Jenkins / Jenkins插件中的错误,还是我遗漏了要点,都应该以其他方式使用Jenkins,我观察到奇怪的意外行为并希望您提供建议。
My task: 我的任务:
I got a freestyle project with an optionally set string parameter. 我有一个带有可选设置的字符串参数的自由式项目。
If the user specifies a value for this parameter, build should use this value. 如果用户为此参数指定一个值,则构建应使用该值。 If the user didn't specify a value, build should compute a value and use it.
如果用户未指定值,则build应计算一个值并使用它。
The resulting value should be used in several other build steps, including shell scripts and triggered builds on other projects. 结果值应在其他几个构建步骤中使用,包括外壳程序脚本和其他项目上的触发构建。
The shortened list of build steps that I have is: 我拥有的构建步骤的简短列表是:
Execute shell 执行外壳
[ -n "$VERSION" ] && echo "VERSION=$VERSION" > new_env || echo "VERSION=12345" > new_env
Inject environment variables, Properties File Path: new_env
注入环境变量,属性文件路径:
new_env
Execute shell 执行外壳
foo "$VERSION"
Trigger/call builds on other project using predefined parameters: upstream_version=$VERSION
使用预定义的参数在其他项目上进行触发/调用:
upstream_version=$VERSION
Problem: 问题:
Now, if the user does not specify a value for VERSION
, 现在,如果用户未为
VERSION
指定值,
upstream_version=12345
(correct) upstream_version=12345
(正确) Feels pretty strange - why does the triggered build receive the new value and the shell script doesn't? 感觉很奇怪-为什么触发的构建不接收新值而shell脚本却不接收?
Jenkins version is 1.625.3. Jenkins版本是1.625.3。
What you need is a way to check if variable is defined and not-empty. 您需要的是一种检查变量是否已定义且非空的方法。 Bash has built in for it.
Bash内置了它。 (-z)
(-z)
if [ -z "$VAR" ];
More details at question in server fault question: How to determine if a bash variable is empty? 服务器故障问题中有疑问的更多详细信息:如何确定bash变量是否为空?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.