Access Stage results in Workflow/ Pipeline plugin

jenkins pipeline set stage status
jenkins pipeline get stage duration
jenkins pipeline example
jenkins stage view api
jenkins pipeline continue on failed stage
pipeline api plugin
jenkins pipeline rest api example
jenkins pipeline steps

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?

Consider this is my current pipeline

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.

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.

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 results in Workflow/ Pipeline plugin, Access Stage results in Workflow/ Pipeline plugin I want the current job to check how many stages have passed in the previous build and log� Pipeline Stage View Plugin. Version history. See the changelog. Stage View: When you have complex build Pipelines, it is useful to be able to see the progress of each stage. The Pipeline Stage View plugin includes an extended visualization of Pipeline build history on the index page of a flow project, under Stage View.

Here is a sample code to iterate all flow nodes and get whatever information you want:

import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker
import org.jenkinsci.plugins.workflow.graph.FlowNode

try {
    // just for demo, a success step and a failure step
    node {
        sh 'true'
        sh 'false'
    }
} finally {
    FlowGraphWalker walker = new FlowGraphWalker(currentBuild.rawBuild.getExecution())
    for (FlowNode flowNode: walker) {
        // do whatever you want with flowNode
        echo flowNode.dump()
    }
}

jenkins, i have pipeline different stages. want current job check how many stages have passed in previous build , log in console? consider current� Event Pipeline in Dynamics 365. The event pipeline allows you to configure when in the event the plug-in code will execute. The event pipeline is divided into the following events and stages: Pre-event/Pre-Validation. This stage executes before anything else, even before basic validation if the triggering action is even allowed based on security.

You can iterate all stages of the build and do what you need:

    WorkflowRun run = Jenkins.instance.getItemByFullName("####YOUR_JOB_NAME####")._getRuns()[0]
    FlowExecution exec = run.getExecution()
    PipelineNodeGraphVisitor visitor = new PipelineNodeGraphVisitor(run)
    def flowNodes = visitor.getPipelineNodes()

    for (Iterator iterator = flowNodes.iterator(); iterator.hasNext();)
    {
        def node = iterator.next()
        if (node.getType() != FlowNodeWrapper.NodeType.STAGE)
        {
            continue;
        }

        String stageName = node.getDisplayName()
        def stageResult = node.getStatus().getResult()

        println "Result of stage ${stageName} is ${stageResult}"
    }

Pipeline: REST API, Provides a REST API to access pipeline and pipeline run data. The Pipeline Stage View plugin includes an extended visualization of Pipeline lookup for changesets with property com.cloudbees.workflow.rest.external. I assume that stage processing will stop as soon as one stage fails. The post clause can then call the email-ext plugin and specify in Subject the stage that failed. Developers will then see quickly which task failed, rather than having to look through the console log (or email body).

Pipeline: Basic Steps, For a list of other such plugins, see the Pipeline Steps Reference page. If the stage result is specified, the message will also be associated with that result and If the time limit is reached, an exception (org.jenkinsci.plugins.workflow.steps. Track Metrics of Pipelines¶ Get Data From Jobs¶. Use Prometheus Push Gateway. via shared lib; JX sh step -> tekton -> write interceptor; Configure Prometheus Push Gateway

Pipeline REST API Plugin, 'https://github.com/jenkinsci/workflow-remote-loader-plugin.git',. 'master', null, '') stage 'Run method from the loaded file' Custom tools plugin was not pipeline friendly The splitTests step analyzes test results from the last successful build of. The Event Execution Pipeline passes registered plug-ins a wealth of data about the current operation being processed and the plug-in's execution environment. For plug-ins. With Plug-ins you can access this data in your code by setting a variable that implements the IPluginExecutionContext interface:

[PDF] No, You Shouldn't Do That! Lessons from Using Pipeline, To access additional information and/or documentation about the step selected, click on the workflow big responsive. Figure 2. CloudBees Pipeline View. The only prerequisite for this plugin is a pipeline with defined stages in the flow. usual post-build steps, such as archiving artifacts or recording JUnit-style test results. Access Stage results in Workflow/ Pipeline plugin. Ask Question Asked 4 years, 2 months ago. Jenkins pipeline: Access individual stage result from upstream job.

Comments
  • Do you have some Groovy code that gets the list of stages and their results? Somehow using the REST API seems like an overkill.
  • Is there a way to get this info in postbuild ?
  • @coding_idiot interesting question, you have the current build number, does the API return anything for it?
  • He asked about get stages info, not about steps. Do have know how to get stages info ?
  • @AdirD stage is a FlowNode whose descriptorId is descriptorId=org.jenkinsci.plugins.workflow.support.steps.StageStep
  • @users3099733, finally i found out the condition :), if (flowNode.getType() == FlowNodeWrapper.NodeType.STAGE)