简体   繁体   中英

Getting the latest execution for a job via the Rundeck API

I'm using the latest version of Rundeck (3.3.10) and I'm having trouble getting the latest execution for a job via the Rest API.

If I call api/38/job//executions?max=1 it doesn't seem to bring back the latest execution if it is still running. Ideally, I'd also like to be able get the latest execution Start Time, End Time, User and result for each job in a single API call, but I'd resigned myself to calling the API once per job. There doesn't seem to be any way to sort the executions you get back from the API - they seem to be sorted by status first, so the running jobs appear at the end of the list.

Does anyone know a way around this? Thanks.

Yo can get that information using: executions?status=running&max=1 call .

Script example:

#!/bin/sh

# protocol
protocol="http"

# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="38"
rdeck_token="YRVaZikt64Am85RyLo1nyq8U1Oe4Q8J7 "

# specific api call info
rdeck_job="03f28add-84f2-4013-b8f5-e48feaf5977c"

# api call
curl --location --request GET "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/job/$rdeck_job/executions?status=running&max=1" \
  --header "Accept: application/json" \
  --header "X-Rundeck-Auth-Token: $rdeck_token" \
  --header "Content-Type: application/json" 

Output:

{
  "paging": {
    "count": 1,
    "total": 1,
    "offset": 0,
    "max": 1
  },
  "executions": [
    {
      "id": 7,
      "href": "http://localhost:4440/api/38/execution/7",
      "permalink": "http://localhost:4440/project/ProjectEXAMPLE/execution/show/7",
      "status": "running",
      "project": "ProjectEXAMPLE",
      "executionType": "user",
      "user": "admin",
      "date-started": {
        "unixtime": 1617304896289,
        "date": "2021-04-01T19:21:36Z"
      },
      "job": {
        "id": "03f28add-84f2-4013-b8f5-e48feaf5977c",
        "averageDuration": 13796,
        "name": "HelloWorld",
        "group": "",
        "project": "ProjectEXAMPLE",
        "description": "",
        "href": "http://localhost:4440/api/38/job/03f28add-84f2-4013-b8f5-e48feaf5977c",
        "permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/03f28add-84f2-4013-b8f5-e48feaf5977c"
      },
      "description": "sleep 20; echo \"hi\"",
      "argstring": null,
      "serverUUID": "630be43c-e71f-4102-be96-d017dd22233e"
    }
  ]
}

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