Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

jenkins

tags

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?

like image 674
dalyons Avatar asked Aug 23 '11 06:08

dalyons


People also ask

Can Jenkins pull code from Git?

With the help of the Git plugin Jenkins can easily pull source code from any Git repository that the Jenkins build node can access.

How do I pass a git branch as parameter in Jenkins?

If you want to be able to dynamically give a Git branch to use in a Jenkins build then you'll need to do a couple of things. Then, in your Pipeline configuration, under Branches to build, add your parameter name inside the Branch Specifier box, surrounded by ${} . Jenkins will expand your variable when the job runs.


2 Answers

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.

like image 157
carlspring Avatar answered Sep 22 '22 13:09

carlspring


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

like image 30
link Avatar answered Sep 24 '22 13:09

link