0

We are working on Azure Devops for CI pipeline on Git master branch. We have Version in our pom.xml file, which need to be updated and pushed to the Git back once the build is successful.

For ex:- <version>0.0.8-SNAPSHOT</version> in pom.xml

When we run
mvn --batch-mode release:prepare release:update-versions -DreleaseVersion=0.0.9 -DpushChanges=true . it should automatically push the updated version to pom.xml in Git master branch

The above command works perfectly when we run it from our local terminal but fails when we run on azure devops with the following error

[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
satya
  • 109
  • 2
  • 13
  • Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance. – Leo Liu-MSFT Oct 16 '19 at 06:44
  • Thanks @LeoLiu-MSFT for the reply. I was already doing the checkout and it was the same issue. Let me try again and update you. – satya Oct 16 '19 at 07:22

1 Answers1

0

Azure Devops - Mvn update-version is not working as part of CI build

According to the document MojoExecutionException, this exception is not generated by the Maven core itself but by a plugin.

For your case, it seems you are using the maven-release-plugin:2.5.2. The cause of the problem seems to be that that plugin checks out the branch in detached head state. HEAD is a pointer which tells you which branch you are on. Pipelines checks out a specific revision/commit when it runs to help test each change to a project, leaving the working copy in "detached head" mode. Maven wants to make additional commits to your repo to record the changes to your pom.xml, and so must be on a branch.

So, to resolve this issue, you can try to reset the branch you want to release from, to the current commit. Assuming you're working from master, you would add command line task at the beginning of your pipeline:

git checkout master

Then, you'll be on head: master, and able to run maven release.

You can check this thread and this thread for some more details.

Hope this helps.

Leo Liu-MSFT
  • 52,692
  • 7
  • 69
  • 81