Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jenkinsfile checkout git tag

I am trying git checkout in Jenkinsfile following way

stage ('Repo Checkout') {
    steps {
        dir('My-Repo') {
            git branch: '${BUILD_BRANCH}',
                credentialsId: 'jenkins',
                url: '[email protected]:my-org/my-repo.git'
        }
    }
}

Is there a way to checkout specific tag in Jenkinsfile ?

like image 846
roy Avatar asked Nov 14 '25 09:11

roy


1 Answers

Try this.

 stage('CheckOut code from git tag') {
      checkout([$class: 'GitSCM', branches: [[name: "refs/tags/v3.0"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: false, reference: '', trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "gitlab-ssh-user", url: "[email protected]:xxxx/xxxxx.git"]]])
 }

Here I am checking out tag v3.0 and in case you want to checkout any branch just mention */branch_name

NOTE: This will work in both scripted and declarative pipeline.

like image 134
Manish R Avatar answered Nov 17 '25 09:11

Manish R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!