一尘不染

Access Stage在工作流/管道插件中产生结果

jenkins

我有一个不同阶段的管道。我希望当前作业检查上一个版本中经过了多少个阶段并将其记录在控制台中?

考虑这是我当前的管道

node(){
 stage "1"
 do something

 stage "2"
 do something else
}

我想要一个时髦的脚本给我这样的东西

println currentBuild.previousBuild.getStage("1").result

我的代码的目的是跟踪构建过程中不同阶段的成功与失败。有没有其他替代方法?


阅读 200

收藏
2020-07-25

共1个答案

一尘不染

您绝对可以使用Pipeline REST API插件,对我来说,Jenkins 2.13 可以直接使用它。

通过解析结果JSON,您可以获得与您期望的状态类似的阶段状态。对于api调用,我个人使用http_request插件。

从文档GET / job /:job-name /:run-id / wfapi / describe返回:

{
    "_links": {
        "self": {
            "href": "/jenkins/job/Test%20Workflow/16/wfapi/describe"
        },
        "pendingInputActions": {
            "href": "/jenkins/job/Test%20Workflow/16/wfapi/pendingInputActions"
        }
    },
    "id": "2014-10-16_13-07-52",
    "name": "#16",
    "status": "PAUSED_PENDING_INPUT",
    "startTimeMillis": 1413461275770,
    "endTimeMillis": 1413461285999,
    "durationMillis": 10229,
    "stages": [
        {
            "_links": {
                "self": {
                    "href": "/jenkins/job/Test%20Workflow/16/execution/node/5/wfapi/describe"
                }
            },
            "id": "5",
            "name": "Build",
            "status": "SUCCESS",
            "startTimeMillis": 1413461275770,
            "durationMillis": 5228
        },
        {
            "_links": {
                "self": {
                    "href": "/jenkins/job/Test%20Workflow/16/execution/node/8/wfapi/describe"
                }
            },
            "id": "8",
            "name": "Test",
            "status": "SUCCESS",
            "startTimeMillis": 1413461280998,
            "durationMillis": 4994
        },
        {
            "_links": {
                "self": {
                    "href": "/jenkins/job/Test%20Workflow/16/execution/node/10/wfapi/describe"
                }
            },
            "id": "10",
            "name": "Deploy",
            "status": "PAUSED_PENDING_INPUT",
            "startTimeMillis": 1413461285992,
            "durationMillis": 7
        }
    ]
}
2020-07-25