脚本失败时退出Jenkins中的构建

时间:2019-03-21 09:36:38

标签: bash jenkins jenkins-pipeline

我正在将Jenkins作为项目的CI / CD管道运行。为了使自己更轻松,我创建了一个bash脚本来运行测试并发送覆盖率报告,这是我的bash脚本:

#!/bin/bash

echo $GIT_COMMIT # only needed for debugging
GIT_COMMIT=$(git log | grep -m1 -oE '[^ ]+$')
echo $GIT_COMMIT # only needed for debugging

./cc-test-reporter before-build
yarn test --coverage
./cc-test-reporter after-build -t simplecov --exit-code $? || echo  “Skipping Code Climate coverage upload”

这就是我在Jenkins中运行它的方式:

sh "jenkins/scripts/load_env_variables.sh test"

Jenkins运行脚本,但是当脚本失败时,Jenkins不会退出,而是继续:

Jenkins build does not exit

对此有任何帮助吗?

1 个答案:

答案 0 :(得分:2)

在脚本中使用“ set -e”。

 -e  Exit immediately if a command exits with a non-zero status.