简体   繁体   English

Jenkins Shell脚本未收到作业参数的新值

[英]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: 我拥有的构建步骤的简短列表是:

  1. Execute shell 执行外壳

     [ -n "$VERSION" ] && echo "VERSION=$VERSION" > new_env || echo "VERSION=12345" > new_env 
  2. Inject environment variables, Properties File Path: new_env 注入环境变量,属性文件路径: new_env

  3. Execute shell 执行外壳

     foo "$VERSION" 
  4. 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指定值,

  • shell script at step 3 receives an empty value (WRONG! well, at least unexpected to me) 第3步的shell脚本收到一个空值(错误!好吧,至少对我来说是意外的)
  • build on other project called with 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.

相关问题 在 jenkins 的可执行 shell 脚本中剪切选择参数值 - cut choice parameter value in executable shell script of jenkins Jenkins将Shell脚本变量传递到下游作业 - Jenkins Passing a Shell Script Variable into a Downstream Job 有没有办法在 shell 脚本中列出 Jenkins 的所有作业,该脚本将作为 Jenkins 作业运行 - Is there a way to list all jobs of Jenkins in a shell script that will be run as a Jenkins job 在Jenkins中-如何在外壳程序脚本中使用“标签”作为参数? - In Jenkins - How to use “label” as a parameter in a shell script? 在声明性管道内的 shell 脚本中传递 Jenkins 参数值时出现错误替换错误 - Bad Substitution error while passing Jenkins Parameter value in shell script inside Declarative pipeline 如何使 Jenkins 找到作业中指定的 shell 脚本 - How to make Jenkins find the shell script which is specified in the job 在 shell 脚本部分的 jenkins 自由式作业中混淆密码 - Obfuscate a password in jenkins freestyle job in section shell script 在詹金斯工作中的shell脚本中的if子句中出现错误 - Getting error in if clause in shell script inside jenkins job 如何将参数传递给UNIX Shell脚本以在UNIX环境中运行作业 - How to Pass parameter to an unix shell script to run a job in an unix environment 可以直接将Jenkins参数(变量)传递到Shell脚本中吗? - Possible to pass a Jenkins Parameter (Variable) directly into a shell script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM