简体   繁体   English

通过 Rundeck API 获取作业的最新执行

[英]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.我正在使用最新版本的 Rundeck (3.3.10),我无法通过 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.如果我调用 api/38/job//executions?max=1 如果它仍在运行,它似乎不会带回最新的执行。 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.理想情况下,我还希望能够在单个 API 调用中获得每个作业的最新执行开始时间、结束时间、用户和结果,但我已经放弃了每个作业调用 API 一次。 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.似乎没有任何方法可以对从 API 返回的执行进行排序 - 它们似乎首先按状态排序,因此正在运行的作业出现在列表的末尾。

Does anyone know a way around this?有谁知道解决这个问题的方法? Thanks.谢谢。

Yo can get that information using: executions?status=running&max=1 call .您可以使用以下方法获取该信息: 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: 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"
    }
  ]
}

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

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