【问题标题】:Azure Devops - Mvn update-version is not working as part of CI buildAzure Devops - Mvn update-version 不能作为 CI 构建的一部分工作
【发布时间】:2020-02-10 23:00:58
【问题描述】:

我们正在为 Git 主分支上的 CI 管道开发 Azure Devops。我们的 pom.xml 文件中有 Version,一旦构建成功,需要更新并推送回 Git。

例如:- <version>0.0.8-SNAPSHOT</version> 在 pom.xml 中

当我们运行时
mvn --batch-mode release:prepare release:update-versions -DreleaseVersion=0.0.9 -DpushChanges=true 。它应该自动将更新的版本推送到 Git master 分支中的 pom.xml

当我们从本地终端运行上述命令时,它可以完美运行,但是当我们在 azure devops 上运行时失败,并出现以下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.2:prepare (default-cli) on project ap-fds-bua-ccc-api: An error is occurred in the checkin process: Exception while executing SCM command. Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
The process '/usr/share/maven/bin/mvn' failed with exit code 1

【问题讨论】:

  • 只是检查提供的信息是否有用。如果您需要进一步的帮助,请告诉我们。
  • 感谢@LeoLiu-MSFT 的回复。我已经在结帐了,这是同样的问题。让我再试一次并更新你。

标签: azure-devops maven-3


【解决方案1】:

Azure Devops - Mvn update-version 不能作为 CI 构建的一部分运行

根据文档MojoExecutionException,这个异常不是由Maven核心本身产生的,而是由插件产生的。

对于您的情况,您似乎正在使用maven-release-plugin:2.5.2。问题的原因似乎是该插件检查了处于分离头状态的分支。 HEAD 是一个指针,它告诉你你在哪个分支上。 Pipelines 在运行时检查特定的修订/提交,以帮助测试对项目的每个更改,使工作副本处于“分离头”模式。 Maven 想要对您的 repo 进行额外的提交以记录对您的 pom.xml 的更改,因此必须在分支上。

因此,要解决此问题,您可以尝试将要从中释放的分支重置为当前提交。假设您在 master 上工作,您将在管道的开头添加命令行任务:

git checkout master

然后,您将处于领先地位:大师,并且能够运行 maven 版本。

您可以查看this threadthis thread 了解更多详情。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2020-09-22
    • 2022-12-13
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    • 2023-01-11
    相关资源
    最近更新 更多