Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70875

stage ( with retry inside ) still active while the build get aborted by `WorkflowRun. finish( .. )`

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • None

      Jenkins build killed by script via https://<hostname>/script:

      Jenkins.instance
             .getItemByFullName( <JOB_NAME> )
             .getBuildByNumber( <BUILD_NUMBER> )
             .finish(
               hudson.model.Result.ABORTED,
               new java.io.IOException( "Aborting build" )
             )
      

      Jenkinsfile

      stage( 'do compile' ) {
        int result = 255
        try {
          retry( count: 2 ) {
            result = sh ( returnStatus: true, script: "make all" )
          }
        } catch ( org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e ) {
          def sw = new StringWriter()
          e.printStackTrace( new PrintWriter(sw) )
          echo sw.toString()
          currentBuild.getRawBuild().getExecutor().interrupt( Result.ABORTED )
        } finally {
          sh " exit ${result} "
        }
      }
      

      result

      • build got aborted
      • stage still keeping "running" ( isActive : true )

      stage detail:

      import org.jenkinsci.plugins.workflow.job.*
      import org.jenkinsci.plugins.workflow.flow.*
      import io.jenkins.blueocean.rest.impl.pipeline.*
      import org.jenkinsci.plugins.workflow.cps.*
      import org.jenkinsci.plugins.workflow.graph.FlowNode
      
      WorkflowRun run = Jenkins.instance
                         .getItemByFullName( <JOB_NAME> )
                         .getBuildByNumber( <BUILD_NUMBER> )
      PipelineNodeGraphVisitor visitor = new PipelineNodeGraphVisitor(run)
      List<FlowNodeWrapper> flowNodes = visitor.getPipelineNodes()
      
      flowNodes.each {
        println """
          ${it.getDisplayName()} stage :
                                getRun() : ${it.getRun()}
                               getResult : ${it.status.getResult()}
                                getState : ${it.status.getState()}
                                 getType : ${it.getType()}
                                   getId : ${it.getId()}
                               isRunning : ${it.node.running}
                                isActive : ${it.node.active}
        """
      }
      
      • result
            compile stage :
                                  getRun() : <JOB_NAME> #126603
                                 getResult : ABORTED
                                  getState : FINISHED
                                   getType : STAGE
                                     getId : 54
                                 isRunning : false
                                  isActive : true                               // <- this is not right
          

      in stage view GUI:

      in pipeline steps:

            Unassigned Unassigned
            marslo Marslo Jiao
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: