我们最近从 SVN 迁移到了 git。除了在 git 上发布其他(意外)问题之外,我想知道如何处理以下问题:
当我在 Jenkins 上开始发布运行并且一些开发人员(意外地)在发布的第一阶段推送时,发布构建失败并出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project xyz: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] To ssh://[some-ip]/home/git/xyz
[ERROR] ! [rejected] release/xyz-6.10 -> release/xyz-6.10 (fetch first)
[ERROR] error: failed to push some refs to 'ssh://[some-ip]/home/git/xyz'
[ERROR] hint: Updates were rejected because the remote contains work that you do
[ERROR] hint: not have locally. This is usually caused by another repository pushing
[ERROR] hint: to the same ref. You may want to first integrate the remote changes
[ERROR] hint: (e.g., 'git pull ...') before pushing again.
[ERROR] hint: See the 'Note about fast-forwards' in 'git push --help' for details.
[ERROR] -> [Help 1]
Jenkins 用于启动发布构建的 maven 命令是(我们在 Windows 上构建,因此我们必须激活
-DautoVersionSubmodules
,否则 git add
上的命令行太长,包括所有修改后的 pom.xml
):mvn -B -DdevelopmentVersion=xyz-6.10.0-rc3-SNAPSHOT -DreleaseVersion=xyz-6.10.0-rc2 -Dtag=xyz-6.10.0-rc2 -Dresume=false -e -Dgoals=deploy -DautoVersionSubmodules=true -DcommitByProject=true -P[some-profiles] -T1C release:prepare release:perform -Darguments=-T1C
有没有一种简单的方法可以阻止其他用户推送(但允许 Jenkins 推送!)?或者任何其他稳定的工作 - 或最佳实践?
使用的版本:
预先感谢您的帮助。
最佳答案
我希望你同意发布失败是正确的。在这种情况下,修复不是一个大问题:更新项目并发布另一个版本。
解决此问题的最简单方法是:沟通 :) 只需通知同事您计划发布此版本。
我听说过的另一个解决方案是:先创建一个分支,然后从该分支发布。没有人会改变分支的内容,所以这应该是一个安全的解决方案,但它需要额外的工作。是否值得由您来决定。大多数时候不是。
关于git - 如何在使用 maven release-plugin 和 git 发布期间避免 "Updates were rejected because the remote contains work"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38220444/