Jenkins pipeline, bash, and pipes

人盡茶涼 提交于 2019-12-07 03:52:07

问题


I have an output string that I want to run a 'tr' and 'jq' command against. Piping makes sense like so, IP= sh(script: "echo $spawnServer | jq .[0] | tr -d '\"'", returnStdout: true) Unfortunately the jenkins pipeline hates pipes, so what I get is

+ tr -d '"'
+ jq '.[0]'
+ echo '[' 172.31.79.253, 'i-0d65b431f18a385d0]'
parse error: Invalid numeric literal at line 1, column 16

Any tips would be great! the only thing I found so far was someone using eval, but that didn't work for me. Any tips would be great!


回答1:


Instead of struggling with quotes and escapes, you could use def, as in:

def command = $/"echo ${spawnServer} | jq .[0] | tr -d '\"'"/$

res = sh(returnStdout: true, script: command).trim()
sh("echo ${res}")


来源:https://stackoverflow.com/questions/47193645/jenkins-pipeline-bash-and-pipes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!