dalyons
dalyons

Reputation: 1304

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

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?

Upvotes: 27

Views: 38621

Answers (3)

carlspring
carlspring

Reputation: 32617

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.

Upvotes: 23

Mihai Rotaru
Mihai Rotaru

Reputation: 1973

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.

Upvotes: 10

link
link

Reputation: 101

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

Upvotes: 10

Related Questions