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

36,757

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
36,757

Related videos on Youtube

dalyons
Author by

dalyons

Updated on July 21, 2020

Comments

  • dalyons
    dalyons almost 4 years

    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?

  • enrique-carbonell
    enrique-carbonell almost 10 years
    i'm trying to use Git Parameter plugin, but for v 0.3.2 not work for release (sha1 of repo)
  • oz10
    oz10 over 9 years
    Out 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.
  • Amedee Van Gasse
    Amedee Van Gasse about 9 years
    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 stackoverflow.com/questions/28543482/…
  • Amedee Van Gasse
    Amedee Van Gasse about 9 years
    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
    Amedee Van Gasse about 9 years
    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
    Amedee Van Gasse about 9 years
    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 stackoverflow.com/questions/28543482/…