Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Git plugin detached HEAD

Tags:

git

jenkins

I am new to Git and also to Jenkins. My problem is that I can't get the Jenkins Maven release plugin to work.

When I build a common Maven build with Jenkins, it works well, but when I try to perform a release with the Maven release plugin, I get the following stack trace:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project parent: 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.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:79)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329)     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)     at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:158)     at hudson.maven.Maven3Builder.call(Maven3Builder.java:98)     at hudson.maven.Maven3Builder.call(Maven3Builder.java:64)     at hudson.remoting.UserRequest.perform(UserRequest.java:118)     at hudson.remoting.UserRequest.perform(UserRequest.java:48)     at hudson.remoting.Request$2.run(Request.java:326)     at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)     at java.util.concurrent.FutureTask.run(FutureTask.java:138)     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)     at java.lang.Thread.run(Thread.java:662) 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:295)     at org.apache.maven.plugins.release.PrepareReleaseMojo.execute(PrepareReleaseMojo.java:247)     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)     ... 27 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:291)     ... 30 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)     ... 38 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)     ... 42 more channel stopped Finished: FAILURE 

The failing command and error message are:

[INFO] Executing: /bin/sh -c cd /var/lib/jenkins/workspace/test_maven/parent && git symbolic-ref HEAD [INFO]  Working directory: /var/lib/jenkins/workspace/test_maven/parent  mojoFailed org.apache.maven.plugins:maven-release-plugin:2.3.2(default-cli) projectFailed ch.apkern.achilles:parent:1.0-SNAPSHOT  sessionEnded 

I have figured out that the Jenkins Git plugin creates a detached HEAD ref "(no branch)" which causes the problem, I think. But I have absolutely no idea why this ref is created or how I can solve this problem.

I would be grateful for any help.

like image 779
Michel Werren Avatar asked Jul 16 '12 19:07

Michel Werren


People also ask

How do I fix a detached head in git?

If you want to keep changes made with a detached HEAD, just create a new branch and switch to it. You can create it right after arriving at a detached HEAD or after creating one or more commits. The result is the same. The only restriction is that you should do it before returning to your normal branch.

Why is Jenkins head detached?

When the Jenkins Git plugin clones a repo, it checks out a specific commit, rather than HEAD of the repo. This puts the repo in a "detached" state, so if you want to perform further git operations on the repo you need to attach to a branch with a checkout command in a shell step.

Why is git head detached?

When you use the git checkout command to view a commit, you'll enter “detached HEAD state”. This refers to when you are viewing a commit that is not the most recent commit in a repository. Detached HEAD state is not an error nor is it a problem. When you are ready, you can navigate back to the HEAD in your repository.


1 Answers

The Checkout/merge to local branch (optional) field is gone in the current (2.2.1) version of the Git plugin.

It has moved to Additional BehavioursCheck out to specific local branch:

Jenkins screenshot of setting option "Check out to specific local branch"

Setting that value to master got me a checked out branch instead of a detached head.

like image 133
Matthias Braun Avatar answered Oct 30 '22 00:10

Matthias Braun