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

Jenkins pipeline fails to properly abort loop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • pipeline
    • None

      1. Linux - Debian
      2. Jenkins 2.204.2
      3. Create pipeline:
        pipeline {
           agent any 
        
           stages {
              stage('Ping') {
                 steps {
                     script {
                       for (def i = 0; i < 500; i++) {
                          echo "currentResult: ${currentBuild.currentResult}"
                          sh "ping 127.0.0.1 -c 1"
                        }
                   }              
                 }
              }
           }
        }
        
      4. run pipeline
      5. Abort pipeline
      6. View build log
        Expected: pipeline aborts
        Actual:
      7. The pipeline gets resumed, without interruption
      1. updated code to see the expected behauvior
        pipeline {
           agent any
        
           stages {
              stage('Ping') {
                 steps {
                     script {
                       for (def i = 0; i < 500; i++) {
                          
                          if (currentBuild.rawBuild.getActions(jenkins.model.InterruptedBuildAction.class).isEmpty()) {
                            echo "currentResult: ${currentBuild.currentResult}"
                        } else {
                            echo "ABORTED"
                            error("aborted")
                        }
                          sh "ping 127.0.0.1 -c 1"
                          
                        }
                   }  
                    
                 }
              }
           }
        }
        

            Unassigned Unassigned
            cwerner Christian Werner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: