如果 BitBucket 中的 webhooks 条件失败,如何停止 repo:push
How to stop repo:push if webhooks condition fails in BitBucket
如果提交语句在备注中没有定义的 Jira 问题 ID,我将尝试停止 Bitbucket 中的回购推送。
我已成功调用 URL 通过 webhooks 检查提交备注,但无法找出在失败时停止推送的方法。
根据 msg-commit
git 挂钩示例自定义以下脚本。
#!/bin/bash
MSG=""
if ! grep -qE "updated" "$MSG";then
cat "$MSG"
echo "Your commit message must contain the word 'updated'"
exit 1
fi
将此代码签入git,然后运行
# give the script "execute" permission
chmod 755 commit-msg
# put the script in the correct place
cp commit-msg .git/hooks/commit-msg
如果您尝试在消息中创建一个没有单词 'updated' 的提交,那么此挂钩将阻止成功创建提交。
来源:https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
The commit-msg hook
takes one parameter, which again is the path to a temporary file that contains the commit message written by the developer. If this script exits non-zero, Git aborts the commit process, so you can use it to validate your project state or commit message before allowing a commit to go through. In the last section of this chapter, We’ll demonstrate using this hook to check that your commit message is conformant to a required pattern.
请注意,克隆您的存储库的任何其他人也需要将挂钩复制到 .git/hooks/commit-msg
对于您的特定用例:
stop the repo push in Bitbucket if the commit statement doesn't have the defined Jira issue id in the remark
它已作为一项功能添加到 Bitbucket Cloud:https://support.atlassian.com/bitbucket-cloud/docs/link-to-a-web-service/#Require-linked-issue-keys-in-commits
您只需打开它即可。
如果提交语句在备注中没有定义的 Jira 问题 ID,我将尝试停止 Bitbucket 中的回购推送。 我已成功调用 URL 通过 webhooks 检查提交备注,但无法找出在失败时停止推送的方法。
根据 msg-commit
git 挂钩示例自定义以下脚本。
#!/bin/bash
MSG=""
if ! grep -qE "updated" "$MSG";then
cat "$MSG"
echo "Your commit message must contain the word 'updated'"
exit 1
fi
将此代码签入git,然后运行
# give the script "execute" permission
chmod 755 commit-msg
# put the script in the correct place
cp commit-msg .git/hooks/commit-msg
如果您尝试在消息中创建一个没有单词 'updated' 的提交,那么此挂钩将阻止成功创建提交。
来源:https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
The
commit-msg hook
takes one parameter, which again is the path to a temporary file that contains the commit message written by the developer. If this script exits non-zero, Git aborts the commit process, so you can use it to validate your project state or commit message before allowing a commit to go through. In the last section of this chapter, We’ll demonstrate using this hook to check that your commit message is conformant to a required pattern.
请注意,克隆您的存储库的任何其他人也需要将挂钩复制到 .git/hooks/commit-msg
对于您的特定用例:
stop the repo push in Bitbucket if the commit statement doesn't have the defined Jira issue id in the remark
它已作为一项功能添加到 Bitbucket Cloud:https://support.atlassian.com/bitbucket-cloud/docs/link-to-a-web-service/#Require-linked-issue-keys-in-commits
您只需打开它即可。