使用Maven发布插件时出现“致命错误:ref HEAD不是符号ref”


104

我在运行Maven版本插件的准备步骤时收到以下错误输出,即 mvn release:prepare --batch-mode -DreleaseVersion=1.1.2 -DdevelopmentVersion=1.2.0-SNAPSHOT -Dtag=v1.1.2 -X从Atlassian Bamboo计划中,。但是,在命令行中执行相同的操作会很好。完整的错误堆栈如下。

有什么想法可以解决吗?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:prepare (default-cli) on project hpcmom: 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]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:prepare (default-cli) on project hpcmom: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.plugins.release.PrepareReleaseMojo.prepareRelease(PrepareReleaseMojo.java:281)
    at org.apache.maven.plugins.release.PrepareReleaseMojo.execute(PrepareReleaseMojo.java:232)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: org.apache.maven.shared.release.ReleaseExecutionException: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.checkin(AbstractScmCommitPhase.java:160)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.performCheckins(AbstractScmCommitPhase.java:145)
    at org.apache.maven.shared.release.phase.ScmCommitPreparationPhase.runLogic(ScmCommitPreparationPhase.java:76)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.execute(AbstractScmCommitPhase.java:78)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:234)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:169)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:146)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:107)
    at org.apache.maven.plugins.release.PrepareReleaseMojo.prepareRelease(PrepareReleaseMojo.java:277)
    ... 22 more
Caused by: org.apache.maven.scm.ScmException: Exception while executing SCM command.
    at org.apache.maven.scm.command.AbstractCommand.execute(AbstractCommand.java:63)
    at org.apache.maven.scm.provider.git.AbstractGitScmProvider.executeCommand(AbstractGitScmProvider.java:291)
    at org.apache.maven.scm.provider.git.AbstractGitScmProvider.checkin(AbstractGitScmProvider.java:217)
    at org.apache.maven.scm.provider.AbstractScmProvider.checkIn(AbstractScmProvider.java:410)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.checkin(AbstractScmCommitPhase.java:156)
    ... 30 more
Caused by: org.apache.maven.scm.ScmException: Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref

    at org.apache.maven.scm.provider.git.gitexe.command.branch.GitBranchCommand.getCurrentBranch(GitBranchCommand.java:147)
    at org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand.createPushCommandLine(GitCheckInCommand.java:192)
    at org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand.executeCheckInCommand(GitCheckInCommand.java:132)
    at org.apache.maven.scm.command.checkin.AbstractCheckInCommand.executeCommand(AbstractCheckInCommand.java:54)
    at org.apache.maven.scm.command.AbstractCommand.execute(AbstractCommand.java:59)
    ... 34 more
[ERROR] 
[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
simple  02-Dec-2013 17:18:09    Failing task since return code of [/opt/dev/apache-maven/3.0.5//bin/mvn -Djava.io.tmpdir=/opt/atlassian/bamboo/5.2.1/temp/HPCMOM-RELEASE-JOB1 release:prepare --batch-mode -DignoreSnapshots=false -DreleaseVersion=1.1.2 -DdevelopmentVersion=1.2.0-SNAPSHOT -Dtag=v1.1.2 -X] was 1 while expected 0

更新:

git ls-remote .在本地工作空间克隆上执行操作将产生:

azg@olympus:~/code/hpcmom$ git ls-remote .
7894eea08a0afecb99515d1339623be63a7539d4    HEAD
7894eea08a0afecb99515d1339623be63a7539d4    refs/heads/master
7894eea08a0afecb99515d1339623be63a7539d4    refs/remotes/origin/HEAD
7894eea08a0afecb99515d1339623be63a7539d4    refs/remotes/origin/master
6a7095b86cccdfd4b28e4dea633d0930809ae9ac    refs/tags/v1.0
1a53462b1ecf0abfea8245016304cda9c78b420d    refs/tags/v1.0^{}
5113a7cbcf35c47b680a9c36e15e5fa01ef1d2e6    refs/tags/v1.1
79a3073ecabe65d3c8051520f8007d9e49a65a06    refs/tags/v1.1^{}
a00249209597ea1214d80ee38f228c40db7022c2    refs/tags/v1.1.0
e892bce8d25d87368ab557fee0d30810bef7e31e    refs/tags/v1.1.0^{}
b491a312c39088533cb069e4ab1ae8a00d1f6bfe    refs/tags/v1.1.2
a3f7618dada7ed60d8190426152ffd90e0e40a86    refs/tags/v1.1.2^{}

这样做git ls-remote .的竹克隆产生:

azg@olympus:/var/atlassian/application-data/bamboo/xml-data/build-dir/HPCMOM-RELEASE-JOB1$ git ls-remote .
2422ce066ac35dae3c54f1435ef8dae5008a9a14    HEAD
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/heads/master
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/remotes/origin/HEAD
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/remotes/origin/master
7539f9700d78a1b766fca7ed9f409914f1ea9d08    refs/tags/vnull
6bfa8c3fdb1f8f56a385035f01b1b77b6e88da8b    refs/tags/vnull^{}

这很奇怪,为什么本地开发克隆的输出与Bamboo的输出如此不同?


4
好的,所以这里的问题是Bamboo下的结帐处于“分离的HEAD”状态。看来Maven试图解析当前分支名称,但失败了,因为在分离的HEAD状态下,HEAD引用不再引用分支名称,而是引用SHA1。您可以通过运行git checkout SHA1或附加^{}ref:的名称在本地进行模拟git checkout HEAD^{}。如果有可能,Bamboo git插件似乎试图检出该分支。看来您参加了一场竞赛:在构建运行之前,出现了新的东西。我还不清楚如何解决它。
John Szakmeister

Answers:


153

我在结合Maven发行插件的Jenkins上遇到了相同的错误,我们通过转到其他行为,检出到特定的本地分支并输入“ master”来修复了该错误

我意识到这不是解决方案,但可以为您提供指导。


3
当您从master分支进行构建时,它可以工作。如果您的分支不同,即使将其更改为特定的分支名称,也无法正常工作。
siddhusingh 2014年

29
我和master在不同的分支上,它也可以工作。我认为问题在于jenkins git插件通常以分离的头部状态签出分支。因此git symbolic-ref命令失败。通过添加Check out to specific local branch我们解决了这个问题。
勒内链接

16
使用**代替master将使本地分支名称与远程分支名称匹配。
neXus

1
根据帮助(Git Plugin-Jenkins-Jenkins Wiki),将字段保留为空也可以解决此问题:“如果选中,并且其值为空字符串或**,则从远程分支计算分支名称,而无需输入源。”
evgeny9

@jvwilge在我的情况下,这是一个共享管道,因此所有设置都来自pom.xml。我如何在代码中编写以下说明:其他行为,

31

对于Jenkins和GIT,请添加其他行为,check out to specific local branch并使用Workspace Cleanup Plugin来清理工作区到CI作业的开始。


1
谢谢,这对我有用。我也需要添加-Darguments="-Dmaven.deploy.skip=true"
timbru31 2015年

@toschneck嗨,我在使用Jenkins和Git时遇到了这个确切的问题。您能否在此处扩展答案,以包括您提到的插件的命令和配置。谢谢。
杰里米

额外清洁工作区的原因是什么?
kap

目前,我进一步移至maven-jgitflow插件。它支持功能和错误修正分支,并具有我见过的最佳发布功能。bitbucket.org/atlassian/jgit-flow/wiki/Home
toschneck

添加“签出到特定的本地分支机构”对我也适用。
约翰琳

11

通过取消选中Use shallow clones带有说明的默认设置,解决了Atlassian Bamboo中的问题Fetches the shallowest commit history possible. Do not use if your build depends on full repository history。该复选框位于计划配置->存储库选项卡-> Git->高级选项下

在此之后,所有发行版都可以正常工作。


5

Use shallow clones在我的情况下,仅取消选中不可用(我正在使用Bamboo 5.7.2)。我还需要Force Clean Build在“源代码签出”任务中启用。启用Use shallow clones可以对作业的下一次执行起作用,但是所有后续执行都会导致相同的错误。


4

我已经在与Maven Release插件一起使用的Bamboo下看到了这个问题。我已通过在“源代码签出”任务中启用选项“强制清洁构建”来解决此问题。Bamboo表示这可能会使构建速度变慢,但是可以正常工作,而且我没有看到任何明显的时间增加。


您使用了哪个版本的Bamboo?我试过了,但是那时候对我没用。
SkyWalker

1
我正在使用5.3内部版本4101-13
zakmck

3

我正在将Jenkins Team Project与Multibranch Project Setup一起使用。

我以前使用过checkout scm命令。

现在,我使用以下代码:

checkout([
                 $class: 'GitSCM',
                 branches: scm.branches,
                 extensions: scm.extensions + [[$class: 'CleanCheckout'], [$class: 'LocalBranch', localBranch: 'new']],
                 userRemoteConfigs: scm.userRemoteConfigs
            ])

1
给它一个赞誉,因为它似乎可以解决问题。但是经过一番修改之后,我注意到它实际上创建了一个名为“ new”的新分支(当与maven release plugin一起使用时)。更正确的方法是改变new**,这使得当地分支机构的名称一样的遥控器。
Tobb

3

对我有用的是在调用“ mvn release”之前先调用“ git checkout -f master”


0

对我们来说,问题在于pom文件中指定的Maven版本。根据竹子中的一个更正了pom文件中指定的maven版本,修复了该问题


0

对于GitHub动作,您可以actions/checkout@v2使用ref: master

steps:
  - uses: actions/checkout@v2
    with:
      ref: master
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.