Jenkins Git Plugin: how to create a specific tag?

I'm having trouble creating Jenkins to create the specified tag. The tag is part of a parameterized assembly, but I don’t know how to pass this through the git plugin to just create this tag. It took 3 hours of my day, and I missed the defeat of the masters when the stack overflowed.

+108
git jenkins
Apr 17 '12 at 17:17
source share
11 answers

I was able to do this using the "branches to build" option:

Branch Specifier (blank for default): tags/[tag-name] 

Replace [tag-name] with the name of your tag.

+192
28 Oct '13 at 10:58 on
source share

None of these answers were sufficient for me using Jenkins CI v.1.555, Git Client Plugin v.1.6.4 and Git Plugin 2.0.4.

I need the task to be created for one Git repository for one specific, fixed (i.e. non-parameterized) tag. I had to assemble a solution from various answers, and “create a Git tag” is quoted by Thilo .

  • Make sure you push your tag to the remote repository using git push --tags
  • In the "Git Repository" section of your assignment, in the "Source Control" section, click "Advanced."
  • In the Refspec field, add the following text: +refs/tags/*:refs/remotes/origin/tags/*
  • In the "Branches for assembly", " */tags/<TAG_TO_BUILD> " section, put */tags/<TAG_TO_BUILD> (replacing <TAG_TO_BUILD> with your actual tag name).

Adding Refspec was critical for me. Although it seemed that the Git repositories were retrieving all the deleted information by default, when I left it empty, the Git plugin, however, could not completely find my tag. Only when I explicitly indicated “get deleted tags” in the Refspec field was there a Git plugin that could identify and build from my tag.

Update 2014-5-7 . Unfortunately, this decision is really associated with an undesirable side effect for Jenkins CI (v.1.555) and the Git à la Stash Webhook repository release notification mechanism for Jenkins : whenever a branch in the repository is updated in push, tag creation tasks work again. This leads to a lot of unnecessary re-construction of the same tags over and over again. I tried to set up tasks with and without the Force polling using workspace parameter, and this seemed to have no effect. The only way I could prevent Jenkins from making unnecessary assemblies for tagging is to clear the Refspec field (i.e. Delete +refs/tags/*:refs/remotes/origin/tags/* ).

If someone finds a more elegant solution, edit this answer with an update. I suspect, for example, that perhaps this will not happen if refspec was definitely +refs/tags/<TAG TO BUILD>:refs/remotes/origin/tags/<TAG TO BUILD> , and not just an asterisk. At the moment, however, this solution works for us, we simply remove the additional Refspec after the successful completion of the task.

+74
Mar 30 '14 at 17:18
source share

Could you tell Jenkins to build from the name Ref? If so, then

 refs/tags/tag-name 

Of all the questions I see about Jenkins and Hudson, I would suggest switching to TeamCity. I did not have to edit the configuration files to get TeamCity working.

+15
Apr 17 2018-12-17T00:
source share

I did something like this and it worked:

 Source Code Management Git Repositories Advance Name: ref Refspec : +refs/tags/*:refs/remotes/origin/tags/* Branches to build Branch Specifier (blank for 'any') : v0.9.5.2 

enter image description here

Jenkins magazine confirmed that it was getting the source from the tag

Check version 0b4d6e810546663e931cccb45640583b596c24b9 (v0.9.5.2)

+9
Oct 09 '15 at 9:55
source share

If you use Jenkins pipelines and want to test a specific tag (for example: a TAG parameter of your assembly), here is what you can do:

 stage('Checkout') { steps { checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: 'YOUR_GIT_REPO_URL.git', credentialsId: 'YOUR_GIT_CREDENTIALS_ID' ]], branches: [[name: 'refs/tags/${TAG}']]], poll: false } } 
+9
Aug 31 '17 at 8:56 on
source share

I set the Advanced-> Refspec field to refs/tags/[your tag name] . It seems simpler than various other offers for Refspec, but for me it worked just fine.

UPDATE 07/23/2014 - In fact, after further testing it turns out that this did not work as expected. It looks like the HEAD version is still being tested. Please cancel this as an accepted answer. In the end, I got a working solution, following the post from gotgenes in this thread (March 30). The problem of unnecessarily starting assemblies mentioned in this post was not a problem for me, since my work was caused by work from the main development branch, and not by an SCM poll.

APR 2018 UPDATE - Please note in the comments that this works for one person and agrees with the Jenkins documentation.

+8
Jul 16 '14 at 22:42
source share

In the latest version of Jenkins (1.639 and higher) you can:

  1. just enter the tag name in the "Branches to build" field.
  2. in a parameterized assembly, you can use the parameter as a variable in the same 'Branches to build' field, i.e. $ {Branch_to_build}.
  3. You can install the Git Parameter Plugin, which will provide you with functionality by listing all available branches and tags.
+7
Dec 02 '15 at 8:27
source share

I managed to get Jenkins to create the tag by installing Refspec and Branch Specifier as detailed in this blog post .

I also had to set the repository name (to “origin” in my case) so that I could refer to it in Refspec (otherwise it would apparently use a randomly generated name).

+3
Jul 24 '13 at 5:46
source share

In the end, I did the following:

  • created a new jenkins-target branch, and got jenkins to keep track of what
  • merges from any branch or label that I want to build on jenkins-target
  • After the assembly worked, transmission checked, etc., just create a tag from the jenkins-target branch

I am not sure that this will work for everyone, my project was quite small, not too many tags and everything, but it’s easy to do dead, no need to mess with refspecs and parameters, etc .:-)

+2
Apr 18 '15 at 9:28
source share

You can even create a tag type, such as 1.2.3-alpha43 , using wildcards:

Refspec: +refs/tags/*:refs/remotes/origin/tags/*

Branch Specifier: origin/tags/1.2.3-alpha*

You can also mark “Build when the change moves to GitHub” to trigger push, but you need to add the “create” action to the web host

+2
Jul 25 '16 at 16:08
source share

I add my two cents here, since I did not see the answer that uses the "Build with options" option in Jenkins.

Here I use the Jenkins CI browser console for the starwars_api project, and I managed to build it directly using Build with Parameters with the value refs / tags / tag-name

  1. select the option "build with parameters".
  2. add value to the field as "refs / tags / tag_142" (tag_name = tag_142 for my example)

enter image description here

0
Jul 02 '19 at 19:45
source share



All Articles