Access Stage results in Workflow/ Pipeline plugin

前端 未结 3 1062
终归单人心
终归单人心 2020-12-30 12:39

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

3条回答
  •  感情败类
    2020-12-30 13:03

    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()
        }
    }
    

提交回复
热议问题