Access Stage results in Workflow/ Pipeline plugin

前端 未结 3 1065
终归单人心
终归单人心 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:14

    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)
            {
                   String stageName = node.getDisplayName()
                   def stageResult = node.getStatus().getResult()
    
                   println "Result of stage ${stageName} is ${stageResult}"
            }
        }
    

提交回复
热议问题