Access Stage的结果在Workflow/Pipeline插件中 [英] Access Stage results in Workflow/ Pipeline plugin

查看:178
本文介绍了Access Stage的结果在Workflow/Pipeline插件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a pipeline with different stages. I want the current job to check how many stages have passed in the previous build and log it in the console?

考虑这是我当前的管道

node(){
 stage "1"
 do something

 stage "2"
 do something else
}

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

I want a groovy script to give my something like this

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

我的代码的目的是跟踪成功&在我的构建中的不同阶段出现故障.此方法是否有其他选择?

The purpose of my code is track successes & failures in different stages across my builds. Are there any alternatives to this approach?

推荐答案

您肯定可以使用

You definitely could use Pipeline REST API Plugin, for me it was available out of the box with Jenkins 2.13.

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

By parsing the resulting JSON you could get the status of the stage similarly to what you expect. For the api call I personally use http_request plugin.

从文档GET/job/:职位名称/:run-id/wfapi/describe返回:

From the documentation GET /job/:job-name/:run-id/wfapi/describe returns:

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

这篇关于Access Stage的结果在Workflow/Pipeline插件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆