git - 如何在使用 maven release-plugin 和 git 发布期间避免 "Updates were rejected because the remote contains work"?

标签 git maven jenkins maven-3 maven-release-plugin

我们最近从 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 推送!)?或者任何其他稳定的工作 - 或最佳实践?

使用的版本:
  • Maven 3.3.9
  • Maven 发布插件 2.5.3
  • Git 2.8.1
  • Jenkins 1.629
  • Jenkins Maven 发布插件插件 0.14.0
  • Windows 10

  • 预先感谢您的帮助。

    最佳答案

    我希望你同意发布失败是正确的。在这种情况下,修复不是一个大问题:更新项目并发布另一个版本。
    解决此问题的最简单方法是:沟通 :) 只需通知同事您计划发布此版本。
    我听说过的另一个解决方案是:先创建一个分支,然后从该分支发布。没有人会改变分支的内容,所以这应该是一个安全的解决方案,但它需要额外的工作。是否值得由您来决定。大多数时候不是。

    关于git - 如何在使用 maven release-plugin 和 git 发布期间避免 "Updates were rejected because the remote contains work"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38220444/

    相关文章:

    配置 Jenkins 编译 git 项目时 JAVA_HOME 设置为无效目录

    Maven 替换器 : replacement value containing dollar signs

    scala - sbt项目的Jenkins静态代码分析

    git - 将本地分支 merge 到master以外的远程分支?

    git - 什么是 `git diff --word-diff' 默认正则表达式?

    git - 如何只将特定标签推送到远程?

    Jenkins 正常运行时间 - 自上次重启以来的时间

    c - 从提交中获取 blob?

    java - 将jar名称设置为包名称开头是否正常

    通过 JNLP 使用 Jenkins 时,iOS 测试不会在模拟器上运行