Jenkins git maven release - git push 失败/更新被拒绝

4
我正在尝试使用git来实现Jenkins的maven release。我遵循了这个指南,但我的发布失败,并出现以下错误。在推送时发生问题。我正在使用工作空间清理插件,所以每次都应该获取项目的新副本。我不确定为什么会出现这个错误。
我试图添加一个预处理步骤,执行"git fetch"和"git pull origin master",但我仍然收到错误信息。似乎它在jenkins工作空间之外创建了本地repo。有人能帮我指向正确的方向吗?
10:44:05 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.2:prepare (default-cli) on project test: Unable to commit files
10:44:05 [ERROR] Provider message:
10:44:05 [ERROR] The git-push command failed.
10:44:05 [ERROR] Command output:
10:44:05 [ERROR] To ssh://abc.example.com/test.git
10:44:05 [ERROR] ! [rejected]          master -> master (fetch first)
10:44:05 [ERROR] error: failed to push some refs to 'ssh://gitlab@abc.example.com/test.git'
10:44:05 [ERROR] hint: Updates were rejected because the remote contains work that you do
10:44:05 [ERROR] hint: not have locally. This is usually caused by another repository pushing
10:44:05 [ERROR] hint: to the same ref. You may want to first integrate the remote changes
10:44:05 [ERROR] hint: (e.g., 'git pull ...') before pushing again.
10:44:05 [ERROR] hint: See the 'Note about fast-forwards' in 'git push --help' for details.
10:44:05 [ERROR] -> [Help 1]

问题出在这里:10:44:05 [ERROR] 提示:更新被拒绝,因为远程包含您所做的工作... - khmarbaise
@khmarbaise,我知道我需要进行git pull,但我不知道在哪里。我正在尝试在工作区目录中,但它显示“已经是最新的”。 - user3847894
我真的不明白为什么我也遇到了这个问题。 自检以来,远程从未发生过任何事情(几秒钟前,Maven发布插件拉取了分支)。 在过去的其他项目中,它对我起作用,但是我无法在当前设置中使用Maven发布插件。 - Merijn Vogel
2个回答

2

我通过创建一个新的jenkins任务来解决了这个问题。之后一切都正常工作了。


0

在进行release:prepare操作的repo分支上,不应该有远程提交。正如这里所提到的,这是与同一repo的其他贡献者之间的沟通问题。

确保您的本地repo是最新的(git pull),然后启动您的mvn命令。

这个GitLab问题也建议:

You could skip pushing back to master and just the commit with the new tag.

Run

mvn release:prepare release:perform -DpushChanges=false
git push —tags

Additional benefit: you do not spoil the master’s commit history with the two release-commits.
Of course now you need to bump your version somehow.
You could use the ci_pipeline_id approach via inclusion of this plugin.


我已经尝试了 git pull,但工作区目录中没有任何更改。 - user3847894
尝试使用mvn -X ...命令,以获取更多日志:您需要检查涉及的是否是主“分支”。 - VonC
是的,我已经尝试过使用mvn -X命令获取调试日志,并且它只使用了主分支。在指定scm时,我使用了git,并将分支设置为"*/master",并选择了"将本地分支检出为主分支"选项。 - user3847894
@user3847894 好的。您能确认您的 master HEAD 提交 (git rev-parse master: https://dev59.com/p2ox5IYBdhLWcg3wl1P4#9110527) 是否与 git ls-remote 返回的提交相同吗? - VonC
@user3847894 那么问题不在您的存储库工作树中(其中一切都是最新的),而在 Jenkins 的工作树中:尝试选择“在构建开始前删除工作区。” 在您的 Jenkins 作业中,如 https://dev59.com/bV4b5IYBdhLWcg3wzUUp#28728663(无需在作业后清理,只需在之前)。 - VonC
在构建开始前删除工作区选项也已启用。让我从头开始尝试。 - user3847894

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接