问题
We re using node configuration in Jenkins.In the Post-build Actions we have Git Publisher which has tags to Push e.g 5.1.0.$BUILD_NUMBER.This now becomes the new build number and is used as the release number for testing
I wanted to access this tag for all the remaining jobs so that I can create the Test report XMLs something with 5.1.0.$BUILD_NUMBER+myjob.xml so that its related to that unique build number.
However I am not sure how can I retrieve the Git tags in all the individual jobs.I am not too sure that I want to use Global variable string property since its a node configuration where on one node/box there a different build and on other there is a different one.The Global property could overwrite the build versions on each other ?
回答1:
If you want to pick a tag when running a new job, you can use the Git Parameter Plugin. With this plugin you have new options when you add parameters to your job.
This plugin allows you to assign git tag or revision number as parameter in Parametrized builds. There is no need to set up anything special, this plugin will read your default configuration from Git Plugin.
It firstly fetching (by git fetch) current repository, and listing all the tags/sha1's to choose from.
You can select the following sorting options for tags/revision/branches/branches_or_tags
- none
- descending
- ascending
- ascending smart
- descending smart
For the smart variants the compare treats a sequence of digits as a single character. Contributed by Graeme Hill.
There is also the Git Tag Message Plugin which, for any build, will discover if any tag is matching the current commit used for the build. If a tag is found, it's name will be set in the GIT_TAG_NAME
environment variable.
Exports the name and message for a git tag as environment variables during a build.
If the revision checked out during a build has a git tag associated with it, its name will be exported during the build as the GIT_TAG_NAME environment variable. If a message was specified when creating the tag (e.g. via git tag -m "..."), then that message will also be exported during the build, as the GIT_TAG_MESSAGE > environment variable.
If the revision has more than one tag associated with it, only the most recent tag will be taken into account. However, if your refspec includes "refs/tags" — i.> e. builds are only triggered when certain tag names or patterns are matched — then the exact tag name that triggered the build will be used, even if it's not the most recent tag for this commit.
来源:https://stackoverflow.com/questions/32390788/how-to-get-the-git-tag-name-in-jenkins-in-node-configuration