Can I get Jenkins to build a git tag from a passed in parameter?

27

6

Jenkins supports parametrized builds.

I have a deployment build that requires the tag to deploy to be specified via a parameter. (to deploy a particular tag to production)

Is there an easy way to do this with the git plugin?

I tried adding a parameter TAG_NAME, and then setting branch_specifier in the git plugin section of the job to $TAG_NAME. Dosen't work. I get:

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

Any ideas?

dalyons

Posted 2011-08-23T06:39:30.927

Reputation: 844

Answers

23

Make the build parameterized and in the git URL box, put the name of the variable you've defined. For example: ${GIT_URL}. This should do it.

carlspring

Posted 2011-08-23T06:39:30.927

Reputation: 17 660

2Out of curiosity, what would the ${GIT_URL} variable look like if the tag is specified as a parameter?

I'm new to Jenkins + Git, sorry for the dumb question. – paxos1977 – 2014-10-09T15:37:25.867

cool, the braces were what I was missing. Cheers. – dalyons – 2011-08-24T02:30:34.393

Heh! Glad to hear it solved the problem! :) – carlspring – 2011-08-24T07:31:37.897

10

Will up oooold topic, since this one is in google's top. Spent some time on this question... Short answer: Extensible choice plugin + groovy script. This allows to make dropdown menu already filled with existing tags.

def gettags = "git ls-remote -t [email protected]:mycompany/com.someproject.git".execute()
def tags = []
def t1 = []
gettags.text.eachLine {tags.add(it)}
for(i in tags)
    t1.add(i.split()[1].replaceAll('\\^\\{\\}', '').replaceAll('refs/tags/', ''))
t1 = t1.unique()
return t1

Long answer here

link

Posted 2011-08-23T06:39:30.927

Reputation: 101

That doesn't work for me. Just like with the Git Parameter Plugin, I don't think that this plugin takes SSH credentials into account. In any case I don't get any items in the dropdown list. – Amedee Van Gasse – 2015-02-17T13:21:13.803

The line that starts with def gettags doesn't work for me because git doesn't know about SSH and I cannot add a .ssh/config file to the jenkins user. See my own answer at http://stackoverflow.com/questions/28543482/jenkins-git-parameter-plugin-cannot-fetch-tags

– Amedee Van Gasse – 2015-02-17T15:11:23.303

9

There's Git Parameter Plugin, which allows you to do exactly that:

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.

Mihai Rotaru

Posted 2011-08-23T06:39:30.927

Reputation: 1 096

i'm trying to use Git Parameter plugin, but for v 0.3.2 not work for release (sha1 of repo) – kikicarbonell – 2014-07-02T19:13:02.843

I am using version 0.4.0 of the Git Parameter plugin, but it doesn't seem to use the SSH credentials for the git server, so it errors out when it tries to fetch all the git tags. See http://stackoverflow.com/questions/28543482/jenkins-git-parameter-plugin-cannot-fetch-tags

– Amedee Van Gasse – 2015-02-17T13:10:20.843

I couldn't get it to work at all so I used the Extensible Choice plugin and a PHP script, see my own answer at the linked question. – Amedee Van Gasse – 2015-02-17T15:09:23.337

2This should be the correct answer IMHO. – Tony Chemit – 2015-12-17T16:27:13.620