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!
There are two types of pipelines in Jenkins: Declarative. Scripted.
If you go to Manage Jenkins --> Configure System you will find an option (called "Shell executable") to set the name or absolute path to the shell that you want your shell scripts to use... For my system without configuring this option... it uses bash!
A Jenkins pipeline can have multiple stages and each stage will be executed by a single agent, all running on a single machine or multiple machines. A pipeline is normally created for a specific branch of source code.
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}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With