没有收到Jenkins的失败邮件

时间:2018-03-13 09:06:46

标签: jenkins jenkins-pipeline

现在使用Jenkins,这是我的帖子构建管道:

pipeline {
agent any
stages {
    stage('Stage 1') {
        steps {
            echo 'Hello this is stage 1'
        }

    }
    stage('Stage 2') {
        steps {
            echo 'Still here? Well this is stage 2'
        }

    }
    stage('Stage 3') {
        steps {
            echo 'Almost there ... stage 3'
        }

    }
    stage('Stage 4 - Python') {
        steps {
            bat 'py atom_python_test.py'
        }

    }
    stage('Stage 5 - Compile C++') {
        steps {
            catchError {
                bat '''
                cd C:\Program Files (x86)//Microsoft Visual Studio 12.0//VC
                call vcvarsall
                cd C://Users//praktikant3//Documents//Visual Studio 2013//Projects//FirstProjectBuiltOnJenkins//FirstProjectBuiltOnJenkins
                dir
                MSBuild.exe
                echo 'Compile Stage successful'
                '''
            }
        }
    }

    stage('Stage 6 - Build C++') {
        steps {
            bat '''
            cd C://Program Files (x86)//Microsoft Visual Studio 12.0//VC
            call vcvarsall
            cd C://Users//praktikant3//Documents//Visual Studio 2013//Projects//FirstProjectBuiltOnJenkins//FirstProjectBuiltOnJenkins
            dir
            MSBuild.exe
            '''
        }

    }

}

post {
    success {
        mail to: 'SomeEMAIL@company.com',
        subject: "Succeeding Pipeline: ${currentBuild.fullDisplayName}",
        body: "All is good with ${env.BUILD_URL}"
    }
    failure {
        mail to: 'SomeEMAIL@company.com',
        subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
        body: "Something is wrong with ${env.BUILD_URL}"
    }
}

}

构建C ++部分是有效的,因为我的语法是正确的,但是在之前的尝试中我使用" \"进行了目录更改。这是行不通的。我添加了一个"编译阶段"使用catchError和其中一个带有" \"看看我是否收到失败通知。根据我的理解:

"您应该将可能失败的每一步都包装到catchError函数中。这样做是:

  • 如果发生错误......
  • ...将build.result设置为FAILURE ...
  • ...并继续构建"

但是当我故意留下反斜杠时,管道失败并停止,并且后块没有执行。

0 个答案:

没有答案