JSON on the command line with jq in Jenkins

I used jq -r '.version' package.json command to filter the version from package.json file using the terminal.

Can we use jq command in Jenkins shell without locally installing it?


2 Answers JSON on the command line with jq in Jenkins

No, in the shell build step, you can only execute commands which are available to the shell therefor you have to install jq on your system and it must be accessible by jenkins.

4 months ago

Instead of using "jq", use the groovy.json.JsonSlurper class to parse the same output that "jq" can parse.

If "jsonStr" is a string variable with legal json content, here's an example using this:

def stuff = new JsonSlurper().parseText(jsonStr).stuff

This will get the "stuff" property in the json string and assign it to the "stuff" variable.

4 months ago