简体   繁体   中英

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: 'git@github.com:my-org/my-repo.git'
        }
    }
}

Is there a way to checkout specific tag in Jenkinsfile ?

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: "git@192.168.44.132: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.

You can speed it up by doing a shallow clone

stage ('Checkout') {
  checkout([
    $class: 'GitSCM',
    branches: [[name: 'refs/tags/v3.0']],
    extensions: [[$class: 'CloneOption', shallow: false, depth: 0, reference: '']],
    userRemoteConfigs: scm.userRemoteConfigs,
  ])
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM