工作流/管道插件中的访问阶段结果 [英] Access Stage results in Workflow/ Pipeline plugin

查看:17
本文介绍了工作流/管道插件中的访问阶段结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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
}

我想要一个 groovy 脚本来给我这样的东西

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?

推荐答案

你绝对可以使用 Pipeline REST API 插件,对我来说,它在 Jenkins 2.13 中开箱即用.

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/:job-name/: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
        }
    ]
}

这篇关于工作流/管道插件中的访问阶段结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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