如何使用 jenkins 修改 git -commit 消息?

How to modify the git -commit messages using jenkins?

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

commit #3
commit #2
commit #1

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

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

其中 XX 将由触发 jenkins 构建的用户完成。 有什么办法吗?到目前为止,我一直无法在网上找到答案。

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

通过压缩解决,使用下面的脚本。 该解决方案将最后一个 (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%"