詹金斯:管道sh不良替代错误 [英] Jenkins: Pipeline sh bad substitution error

查看:131
本文介绍了詹金斯:管道sh不良替代错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的管道中的一个步骤将.tar上传到人工服务器.传入env.BUILD_NUMBER时出现错误替换错误,但是当数字被硬编码时,相同的命令也起作用.该脚本通过jenkins用groovy编写,并在jenkins工作区中运行.

A step in my pipeline uploads a .tar to an artifactory server. I am getting a Bad substitution error when passing in env.BUILD_NUMBER, but the same commands works when the number is hard coded. The script is written in groovy through jenkins and is running in the jenkins workspace.

sh 'curl -v --user user:password --data-binary ${buildDir}package${env.BUILD_NUMBER}.tar -X PUT "http://artifactory.mydomain.com/artifactory/release-packages/package${env.BUILD_NUMBER}.tar"'

返回错误:

[Pipeline] sh
[Package_Deploy_Pipeline] Running shell script
/var/lib/jenkins/workspace/Package_Deploy_Pipeline@tmp/durable-4c8b7958/script.sh: 2: 
/var/lib/jenkins/workspace/Package_Deploy_Pipeline@tmp/durable-4c8b7958/script.sh: Bad substitution
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
ERROR: script returned exit code 2

如果在内部版本号中添加硬代码并换出了${env.BUILD_NUMBER},我没有任何错误,并且代码成功运行.

If hard code in a build number and swap out ${env.BUILD_NUMBER} I get no errors and the code runs successfully.

sh 'curl -v --user user:password --data-binary ${buildDir}package113.tar -X PUT "http://artifactory.mydomain.com/artifactory/release-packages/package113.tar"'

我在同一脚本中的其他sh命令中使用了$ {env.BUILD_NUMBER},在其他任何地方都没有问题.

I use ${env.BUILD_NUMBER} within other sh commands within the same script and have no issues in any other places.

推荐答案

这原来是语法问题.将命令包装在'中会导致传递${env.BUILD_NUMBER而不是其值.我将整个命令包装在"中,并逃脱了嵌套.现在可以正常工作.

This turned out to be a syntax issue. Wrapping the command in ''s caused ${env.BUILD_NUMBER to be passed instead of its value. I wrapped the whole command in "s and escaped the nested. Works fine now.

sh "curl -v --user user:password --data-binary ${buildDir}package${env.BUILD_NUMBER}.tar -X PUT \"http://artifactory.mydomain.com/artifactory/release-packages/package${env.BUILD_NUMBER}.tar\""

这篇关于詹金斯:管道sh不良替代错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆