jenkinsfile签出git标签

时间:2019-03-01 22:33:32

标签: jenkins jenkins-pipeline

我正在尝试按照以下方式在Jenkinsfile中进行git checkout

stage ('Repo Checkout') {
    steps {
        dir('My-Repo') {
            git branch: '${BUILD_BRANCH}',
                credentialsId: 'jenkins',
                url: 'git@github.com:my-org/my-repo.git'
        }
    }
}

是否可以检出Jenkinsfile中的特定标签?

2 个答案:

答案 0 :(得分:1)

尝试一下。

 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"]]])
 }

我在这里签出标签v3.0,如果您想签出任何分支,只需提及*/branch_name

注意:这将同时在脚本和声明管道中起作用。

答案 1 :(得分:0)

您可以通过浅表克隆来加快速度

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