Jenkins:由于提交消息而避免构建

use*_*295 9 jenkins jenkins-plugins

由于特殊的提交消息模式,是否可以取消或跳过Jenkins中的作业?我认为工作配置中的"Excluded Commit comments"选项可以为我提供开箱即用的功能,就像这里提到的那样.但无论我在这个领域写的是哪个正则表达式,都会执行构建.

例如:仅当提交消息包含表达式"release"时,我才想执行构建作业.所以我在Excluded Commit comments字段中编写正则表达式[^(?: release)].我想如果我提交一个修订版,例如"test commit",那么build-job不会执行,对吧?这是不使用post-commit钩子的正确方法吗?

小智 5

Jenkins Git 插件向您公开环境变量GIT_COMMIT,其中当然包含当前的 git 提交哈希值。使用 [Jenkins Conditional Step] 并构建一个执行以下 bash shell 的步骤:

echo "==========================="

if [ "git show $GIT_COMMIT | grep "your-pattern-here" == false  ] ; then
        echo "pattern failed";
        exit 1
else
        echo "ok"
fi

echo "==========================="
Run Code Online (Sandbox Code Playgroud)

并标记如果 shell 失败,则构建失败。

  • 我认为上面的代码很接近,但不太正确。这对我有用... `code` if [[ $(git show $GIT_COMMIT | grep "[要跳过提交的字符串]" | wc -m) -ne 0 ]] ; 然后 echo "跳过此提交" exit 0 else echo "确定构建" fi `code` (2认同)