0

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

DoThe New
  • 11
  • 2
  • Are you bound to a plain API call? Have you considered using a tool like [jq](https://stedolan.github.io/jq/tutorial/) to extract the information you need from the JSON? – criztovyl Jul 17 '22 at 16:25
  • I can explore that too.. if it makes life easier and i have to see if I can call using uipath – DoThe New Jul 18 '22 at 18:17

1 Answers1

1

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
ycr
  • 12,828
  • 2
  • 25
  • 45