简体   繁体   English

Jenkins REST API:从响应中获取特定的 json 元素

[英]Jenkins REST API: get specfic json element from the response

I want to just get the "value" field from the actions's parameters from response using the REST API:我想从使用 REST API 的响应中的操作参数中获取“值”字段:

value" : "PROJECT.47"价值”:“PROJECT.47”

"value" : "PROJECT.54" “价值”:“PROJECT.54”

I am using following query that gives me the first of the actions but can't just get the value element.我正在使用以下查询,它为我提供了第一个操作,但不能只获取 value 元素。

http://10.100.6.52:8080/jenkins/view/Deployment/api/json?tree=jobs[displayName,lastBuild[actions[*[*]{1}]{0}]]&pretty=true http://10.100.6.52:8080/jenkins/view/Deployment/api/json?tree=jobs[displayName,lastBuild[actions[*[*]{1}]{0}]]&pretty=true

Jenkins API Response:詹金斯 API 响应:

{
  "_class" : "hudson.model.ListView",
  "jobs" : [
    {
      "_class" : "hudson.model.FreeStyleProject",
      "displayName" : "Batch_Dep",
      "lastBuild" : {
        "_class" : "hudson.model.FreeStyleBuild",
        "actions" : [
          {
            "_class" : "hudson.model.ParametersAction",
            "parameters" : [
              {
                "_class" : "hudson.model.StringParameterValue",
                "name" : "release",
                "value" : "PROJECT.47"
              }
            ]
          }
        ]
      }
    },
    {
      "_class" : "hudson.model.FreeStyleProject",
      "displayName" : "PROJECT_Execution",
      "lastBuild" : {
        "_class" : "hudson.model.FreeStyleBuild",
        "actions" : [
          {
            "_class" : "hudson.model.ParametersAction",
            "parameters" : [
              {
                "_class" : "hudson.model.StringParameterValue",
                "name" : "release",
                "value" : "PROJECT.54"
              }
            ]
          }
        ]
      }
    },

PS: Referred following posts : PS:参考以下帖子:

https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

https://www.cloudbees.com/blog/taming-jenkins-json-api-depth-and-tree https://www.cloudbees.com/blog/taming-jenkins-json-api-depth-and-tree

Check the following.检查以下内容。 Instead of passing the lastBuild to the filter tree, I'm getting the lastBuild directly and filtering here.我没有将lastBuild传递给过滤器树,而是直接获取 lastBuild 并在此处进行过滤。

http://JENKINS_URL/job/YOURJOB/lastBuild/api/json?tree=displayName,actions[parameters[value]]&pretty=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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