1

I'm using the Maven Release Plugin and I'm trying to tag every release with my Jenkins build number.

I've tried this from pom.xml:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.5.3</version>
        <configuration>
          <tagNameFormat>${env.BUILD_NUMBER}</tagNameFormat>
        </configuration>
      </plugin>

And also from Jenkins when I'm calling Maven:

mvn release:prepare -tag=${env.BUILD_NUMBER}

However, I'm getting:

Unable to tag SCM
[ERROR] Provider message:
[ERROR] The git-tag command failed.
[ERROR] Command output:
[ERROR] fatal: tag 'my-project-1.3' already exists

I'm not sure what 1.3 stands for.

So how can I tag the release? I am doing any mistake?

bsky
  • 19,326
  • 49
  • 155
  • 270

1 Answers1

5

Your pom is probably on version 1.3-SNAPSHOT

mvn release:prepare

Will update the version to 1.3, create the git tag "artifactid-version" in your case my-project-1.3, then set the version in your pom to 1.4-SNAPSHOT for the next iteration.

To fix your problem delete the tag see How to delete a git remote tag? then run mvn release:prepare again.

You may need to set your version back to 1.3-SNAPSHOT, this can be done with

mvn versions:set -DnewVersion=1.3-SNAPSHOT

Or just edit you pom/poms.

Community
  • 1
  • 1
Essex Boy
  • 7,565
  • 2
  • 21
  • 24
  • If I do `mvn release:prepare` multiple times, the version still remains `1.3` and isn't incremented. Any idea why? – bsky Mar 10 '17 at 15:26
  • 1
    @octavian The version will be changed to 1.4-SNAPSHOT after the git tag, so it that command fails this will not happen. – Essex Boy Mar 10 '17 at 15:41
  • Can I do something like `mvn release:prepare -DnewVersion=${env.BUILD_NUMBER}`, where `BUILD_NUMBER` is the build number from Jenkins? I would like to specify a version depending on the Jenkins build number but I don't know how. – bsky Mar 10 '17 at 15:47
  • @octavian you are getting away from the idea of a "release" in maven terms. A release is intended to be done rarely, say at the end of a sprint, The version should be decided by the project. Perhaps you don't really want to do a release? Remember you still have all you git commits which you can go back to if needed. HTH. – Essex Boy Mar 10 '17 at 15:50
  • In the end, I will not do a release for every build. I will do a release only in some cases. However, I would like to have the build number in the name as well. – bsky Mar 10 '17 at 15:52
  • @octavian mvn:release:prepare will tag and update the version, mvn release:perform will install the released/tagged version in your repository (Nexus or similar). This is then an immutable binary artifact which is linked to a source code state by the git tag. Why do you need the build number? You can return the the source with a simple "git checkout my-project-1.3" – Essex Boy Mar 10 '17 at 15:57