2

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?

Janith
  • 217
  • 1
  • 6
  • 15

2 Answers2

3

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.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199
1

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.

JGK
  • 3,710
  • 1
  • 21
  • 26
  • Can't we use a plugin for that? Then I need to install `jq` in the local server for executing Jenkins Shell. – Janith Nov 09 '18 at 08:07
  • https://stackoverflow.com/questions/37062872/how-to-parse-json-response-in-a-built-step-in-jenkins – JGK Nov 09 '18 at 09:32