如何在jenkins中的内置步骤中解析JSON响应 [英] How to parse JSON response in a built step in jenkins

查看:863
本文介绍了如何在jenkins中的内置步骤中解析JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了工业化IBM产品的部署,我将使用其REST API接口. 我计划使用jenkins来协调对REST API的调用. 我仍然想知道这是否是个好主意...? 如果是这样,是否有任何方法可以简单地解析JSON响应,以便能够在步骤中创造一些条件? 谢谢.

In order to industrialize the deployments of an IBM product, I'm going to use its REST API interfaces. I plan to use jenkins in order to orchestrate the calls to the REST APIs. I'm still wondering if it's a good idea...? If so, is there any way to simply parse the JSON responses in order to be able to make some conditions in the steps? Thanks.

推荐答案

您没有说您使用API​​的目的,但是如果您有

You didn't say what you're using the API for, but if you have the Groovy plugin, you could use JsonSlurper

类似

import groovy.json.JsonSlurper
URL apiUrl = "https://some.website/api/someFunction".toURL()
List json = new JsonSlurper().parse(apiUrl.newReader())

// do stuff with the json object

不过,我不太确定如何将其用于工作执行期间的有条件构建步骤 .

I'm not quite sure how you would take this and use it directly for conditional build steps during the execution of the job, though.

另一种方法是使用作业DSL插件.这种事情可以用于诸如读取SCM分支列表并为每个分支生成作业之类的事情.那可能是,也可能不是你想要的.

An alternative approach is to generate a set of jobs with the appropriate steps based on the API response, using the Job DSL Plugin. This sort of thing can be used for stuff like reading a list of SCM branches and generating jobs for each of them. That may or may not be what you're trying to do.

这篇关于如何在jenkins中的内置步骤中解析JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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