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

Nested stages go out of order when skipped using restart from stage

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Pipeline stage view plugin v2.19

      Here is a sample pipeline, there are nested stage to make sure env is locked during deployment and verification. The stages appear in sequence when nested stages are executed.

      When the pipeline is restarted using "Restart from Stage" and a later stage is picked, e.g. a prod one. Then, the nested stage go out of order. Images attached
       

      def deployToProd = false
      
      pipeline {
          agent none
      
          options {
              timestamps()
              buildDiscarder(logRotator(numToKeepStr: '20'))
              skipStagesAfterUnstable()
              timeout time: 30, unit: 'MINUTES'
          }
      
          stages {
              stage('Build') {
                  agent none
                  steps {
                      script {
                          println 'in build stage'
                      }
                  }
              }
              stage('Lock dev') {
                options {
                      lock resource: "${JOB_NAME}-dev", quantity: 1, variable: 'deployEnv'
                }
                when {
                          beforeOptions true
                          beforeAgent true
                          branch 'master'
                      }
                stages {
                  stage('Deploy to dev') {
                      when {
                          beforeOptions true
                          beforeAgent true
                          branch 'master'
                      }
                      agent none
                      steps {
                          script {
                              println 'in deploy to dev stage'
                          }
                      }
                  }
                  stage('testing in dev') {
                      when {
                          beforeOptions true
                          beforeAgent true
                          branch 'master'
                      }
                      agent none
                      steps {
                          script {
                              println 'run tests in dev'
                          }
                      }
                  }
                }
              }
      
              stage('Lock test') {
                options {
                      lock resource: "${JOB_NAME}-test", quantity: 1, variable: 'deployEnv'
                }
                stages {
                  stage('Deploy to test') {
                      when {
                          beforeAgent true
                          branch 'master'
                      }
                      agent none
                      steps {
                          script {
                              println 'in deploy to test stage'
                          }
                      }
      
                  }
      
                  stage('testing in test') {
                      when {
                          beforeAgent true
                          branch 'master'
                      }
                      agent none
                      steps {
                          script {
                              println 'run tests in test'
                          }
                      }
                  }
                }
              }
      
      
              stage('Approve prod?') {
                  when {
                      beforeAgent true
                      branch 'master'
                  }
                  agent none
                  steps {
                      script {
                          def proceed = true
                          try {
                              timeout(time: 10, unit: 'SECONDS') {
                                  input(message: 'Deploy this build to PROD?')
                              }
                          } catch (err) {
                              proceed = false
                          }
                          if (proceed) {
                              deployToProd = true
                          }
                      }
                  }
              }
              
              stage('Deploy to prod') {
                options {
                      lock resource: "${JOB_NAME}-prod", quantity: 1, variable: 'deployEnv'
                }
                  when {
                      beforeAgent true
                      branch 'master'
                      expression { return deployToProd }
                  }
                  agent none
                  steps {
                      script {
                          println 'in deploy to prod stage'
                      }
                  }
              }
      
          }
      }
      
      

       

       

        1. stages-in-order.png
          17 kB
          Mustansar Anwar ul Samad
        2. stages-out-of-order.png
          14 kB
          Mustansar Anwar ul Samad

            Unassigned Unassigned
            mustansar Mustansar Anwar ul Samad
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: