简体   繁体   中英

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?

不可以,在shell构建步骤中,您只能执行外壳可用的命令,因此您必须在系统上安装jq ,并且jenkins必须可以访问它。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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