简体   繁体   English

Jenkins管道,bash和管道

[英]Jenkins pipeline, bash, and pipes

I have an output string that I want to run a 'tr' and 'jq' command against. 我有一个输出字符串,我想对它运行'tr'和'jq'命令。 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 这样的管道有意义, IP= sh(script: "echo $spawnServer | jq .[0] | tr -d '\\"'", returnStdout: true)不幸的是,詹金斯管道讨厌管道,所以我得到的是

+ 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. 到目前为止,我唯一发现的是使用eval的人,但这对我不起作用。 Any tips would be great! 任何提示都很棒!

Instead of struggling with quotes and escapes, you could use def , as in: 除了使用引号和转义符,还可以使用def ,如下所示:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM