简体   繁体   中英

How to create a release number in Jenkins from a Git tag?

How can I set the version of a Jenkins build based on a Git tag?

What I am currently doing:

  1. Use the Maven versions plugin to set the release version of the current build from the Jenkins build number, eg newVersion=1.1.$BUILD_NUMBER
  2. Build and deploy the project using Maven
  3. Use Git Publisher to tag the build in Git using the build number, eg MYPROJECT_BUILD-1.1.$BUILD_NUMBER

What I would like to do: Instead of using the Jenkins BUILD_NUMBER, I would like to extract the last build number from the Git tag and increment it

  1. Get the latest tag from Git that matches a given pattern, such as MYPROJECT_BUILD-.*
  2. Extract the build number from the tag and increment it
  3. Build and deploy the project using Maven
  4. Use Git Publisher to tag the build in Git using the incremented build number, eg MYPROJECT_BUILD-1.1.124

What is the best way to achieve this?

Git doesn't really know about Maven. Is there any specific reason why Git should drive the numbering?

Maven is IMHO the better choice. It knows about your source control (if you have configured <scm> correctly) and knows what the version is and if it's a release or a snapshot.

With the combination of Maven + Git + Jenkins we are very happy with the Release plugin : It takes your snapshot, does a Maven release and tags it in Git, and commits the change to the next snapshot (you define that version number).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM