Jenkins REST API: get specfic json element from the response

1.2k Views Asked by At

I want to just get the "value" field from the actions's parameters from response using the REST API:

value" : "PROJECT.47"

"value" : "PROJECT.54"

I am using following query that gives me the first of the actions but can't just get the value element.

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

Jenkins API Response:

{
  "_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 :

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

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

1

There are 1 best solutions below

0
ycr On

Check the following. Instead of passing the lastBuild to the filter tree, I'm getting the lastBuild directly and filtering here.

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