无法在Jenkins管道中运行Shell脚本 [英] Unable to run shell script inside Jenkins pipeline
本文介绍了无法在Jenkins管道中运行Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够运行以下shell脚本,但无法从Jenkins管道代码运行.
I'm able to run the following shell script but couldn't run from Jenkins pipeline code.
尝试1.
node('buildnode') {
def value = "Myvalue"
def key = "Mykey"
sh '''
DATA=$(printf "%-50s \"$key\"" "$value")
echo "$DATA"
'''
}
输出:
++ printf '%-50s ' ''
+ DATA='
尝试2:
尝试过sh""
DATA=$(printf "%-50s \"$key\"" "$value")
echo "$DATA"
" " "
输出::
美元符号后的非法字符串体字符; 解决方案:逸出文字美元符号
"\$5"
或将值表达式"${5}"
illegal string body character after dollar sign; solution: either escape a literal dollar sign
"\$5"
or bracket the value expression"${5}"
有人可以帮助我吗?
推荐答案
这应该有效.
node('buildnode') {
def value = "Myvalue"
def key = "Mykey"
sh """
DATA=\$(printf "%-50s \"${key}\" \"${value}\"")
echo "\$DATA"
"""
}
在""" """
DATA=$(printf "%-50s \"${key}\" \"${value}\"")
这篇关于无法在Jenkins管道中运行Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文