Jenkins文件执行sh,无法转义双引号字符

时间:2019-03-04 09:37:35

标签: shell jenkins jenkins-pipeline

我有一个描述管道的jenkinsfile。

在我的其中一个步骤中,我试图从像这样的卷曲中分配一个值:

sh '''
value=$(curl "http://someUrl/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
//some commands
'''

但是以某种方式调用

curl 'http://someUrl.com/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,:,//crumb)'

代替

curl 'http://someUrl.com/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'

因此导致错误,我想在shell中转义字符必须使用'\',我的命令出了什么问题?

(我在gitbash中尝试了具有良好效果的curl)

1 个答案:

答案 0 :(得分:0)

使用三元'\'有效:

value=$(curl "http://someUrl/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\\\":\\\",//crumb)")
相关问题