Abort current build from pipeline in Jenkins

后端 未结 7 1359
时光说笑
时光说笑 2020-12-02 13:06

I have a Jenkins pipeline which has multiple stages, for example:

node(\"nodename\") {
  stage(\"Checkout\") {
    git ....
  }
  stage(\"Check Preconditions         


        
相关标签:
7条回答
  • 2020-12-02 13:43

    I handled in a declarative way as shown below:

    Based on catchError block it will execute post block. If post result falls under failure category, the error block will be executed to stop upcoming stages like Production, PreProd etc.

    pipeline {
    
      agent any
    
      stages {
        stage('Build') {
          steps {
            catchError {
              sh '/bin/bash path/To/Filename.sh'
            }
          }
          post {
            success {
              echo 'Build stage successful'
            }
            failure {
              echo 'Compile stage failed'
              error('Build is aborted due to failure of build stage')
    
            }
          }
        }
        stage('Production') {
          steps {
            sh '/bin/bash path/To/Filename.sh'
          }
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题