首页 > 解决方案 > 如何使用 jenkins 修改 git -commit 消息?

问题描述

我正在使用 Jenkins 服务器来检查主服务器上的构建和合并。现在我想实现它,以便它使用自定义字符串修改提交消息。具体例子:假设我在一个分支上做了 3 次提交;

commit #3
commit #2
commit #1

我想做的是更改这些消息,使它们看起来像

ISSUE-XX commit #3
ISSUE-XX commit #2
ISSUE-XX commit #1

其中 XX 将由用户触发 jenkins 构建完成。有没有办法做到这一点?到目前为止,我还没有在网上找到答案。

我已经考虑过实现 git-hooks 但这并不是我想要的,我也考虑过自动变基,但我不太明白。

标签: gitjenkinsgithubmessagecommit

解决方案


使用下面的脚本解决了挤压问题。该解决方案将最后一个 (NUMBER_OF_COMMITS) 压缩为一个作为构建参数给出的单个,并设置自定义提交消息,也作为构建参数给出。

    ::Rebasing to modify commit messages

    :: Reset the current branch to the commit just before the last 12:
    git reset --hard HEAD~%NUMBER_OF_COMMITS%

    :: HEAD@{1} is where the branch was just before the previous command.
    :: This command sets the state of the index to be as it would just
    :: after a merge from that commit:
    git merge --squash HEAD@{1}

    :: Commit those squashed changes.
    git commit -m "%ISSUE%"

推荐阅读