Jenkins管道,bash和管道 [英] Jenkins pipeline, bash, and pipes

查看:104
本文介绍了Jenkins管道,bash和管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输出字符串,我想对它运行'tr'和'jq'命令.管道这样有意义,IP= sh(script: "echo $spawnServer | jq .[0] | tr -d '\"'", returnStdout: true)不幸的是,詹金斯管道讨厌管道,所以我得到的是

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

任何提示都很棒!到目前为止,我发现的唯一东西是使用eval的人,但这对我不起作用.任何提示都很棒!

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!

推荐答案

您可以使用def,而不是用引号和转义来代替,

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}")

这篇关于Jenkins管道,bash和管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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