【发布时间】:2018-10-02 20:44:47
【问题描述】:
我试图让我的 Jenkins 在 junit 测试失败时发送一条 Slack 消息,但是当测试失败时它不会执行任何其他操作。
我在 Multibranch Pipeline 工作的 Jenkinsfile 中使用脚本化管道。
这是管道中的测试阶段:
node {
// setup and build Docker image
stage("Test") {
slackSend message: "Running tests!"
sh("docker run --rm -i \
-v '${env.WORKSPACE}/tests/results/':/tmp/tests/results \
${image} python3 manage.py test")
try {
slackSend message: "Checking tests!"
junit 'tests/results/*.xml'
} catch(err) {
slackSend message: "Error in tests!"
} finally {
slackSend message: "Finally in tests!"
}
}
}
我故意添加了一个会失败的测试用例。我希望看到所有四个 Slack 消息:Running tests!、Checking tests!、Error in tests! 和 Finally in tests!,但我看到的只是 Running tests!,即使 Checking 消息出现在 junit 之前行。
如果测试没有任何失败,那么我会看到Running、Checking 和Finally Slack 消息,正如我所料。
为什么 junit 测试失败时try/catch 不执行?
【问题讨论】: