【问题标题】:Getting the latest execution for a job via the Rundeck API通过 Rundeck API 获取作业的最新执行
【发布时间】:2021-04-01 16:32:55
【问题描述】:

我正在使用最新版本的 Rundeck (3.3.10),我无法通过 Rest API 获取作业的最新执行。

如果我调用 api/38/job//executions?max=1 ,如果它仍在运行,它似乎不会恢复最新的执行。理想情况下,我还希望能够在单个 API 调用中获得每个作业的最新执行开始时间、结束时间、用户和结果,但我已经辞职,每个作业调用一次 API。似乎没有任何方法可以对从 API 返回的执行进行排序 - 它们似乎首先按状态排序,因此正在运行的作业出现在列表的末尾。

有人知道解决这个问题的方法吗?谢谢。

【问题讨论】:

    标签: rundeck


    【解决方案1】:

    您可以使用以下方式获取该信息:executions?status=running&max=1call

    脚本示例:

    #!/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" 
    

    输出:

    {
      "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"
        }
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 2023-02-08
      • 2013-08-31
      • 1970-01-01
      相关资源
      最近更新 更多