Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout repository based on Tag in the Jenkins Workflow plugin

With the Jenkins Workflow Plugin, I can checkout a repository based on branch. However, I would like to checkout a repository based on a tag.

This is my current configuration for checking out the master branch

node {
    git url: src, branch: 'master'
}

Now I would like to achieve to check out tag 3.6.1. I tried to change the branch to a tag, but that won't work. Neither is there something in the documentation regarding checking out on tag.

Is this currently possible? Am I overseeing something?

references;

https://github.com/jenkinsci/workflow-plugin

https://github.com/jenkinsci/workflow-plugin/blob/master/scm-step/README.md

https://github.com/jenkinsci/workflow-plugin/blob/master/scm-step/src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GitStep/config.jelly

https://github.com/jenkinsci/workflow-plugin/blob/master/scm-step/src/main/java/org/jenkinsci/plugins/workflow/steps/scm/GitStep.java

like image 438
P.T. Avatar asked Dec 23 '15 13:12

P.T.


People also ask

How do I checkout a tag?

In order to checkout a Git tag, use the “git checkout” command and specify the tagname as well as the branch to be checked out. Note that you will have to make sure that you have the latest tag list from your remote repository.

What is checkout scm in Jenkins?

1. The checkout step will checkout code from source control; scm is a special variable which instructs the checkout step to clone the specific revision which triggered this Pipeline run.

What is GitSCM in Jenkins?

$class: 'GitSCM' The git plugin provides fundamental git operations for Jenkins projects. It can poll, fetch, checkout, and merge contents of git repositories. The git plugin provides an SCM implementation to be used with the Pipeline SCM checkout step.


2 Answers

Just found the answer myself by crawling through the issue list. Seems like they won't change it; https://issues.jenkins-ci.org/browse/JENKINS-27018

This is the suggested solution;

checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: src]], branches: [[name: 'refs/tags/3.6.1']]], poll: false
like image 80
P.T. Avatar answered Sep 29 '22 10:09

P.T.


This works:

checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: repoURL, 
credentialsId: credential]], branches: [[name: tag-version]]],poll: false

Not This:

checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: repoURL], 
[credentialsId: credential]], branches: [[name: tag-version]]],poll: false
like image 35
rashidcmb Avatar answered Sep 29 '22 10:09

rashidcmb