简体   繁体   English

在 Jenkins 管道中签出标签

[英]Checkout a tag in Jenkins pipeline

Tried using尝试使用

checkout scm: [$class: 'GitSCM', 
  userRemoteConfigs: [[url: '${repoURL}']], 
  branches: [[name: 'refs/tags/${tag-version}']]],poll: false

This fails with an Authentication error.这会因身份验证错误而失败。 Is there any way other than using除了使用还有什么办法

withCredentials有凭证

to checkout tag in a Jenkinsfile在 Jenkinsfile 中签出标签

After spending, hours got here消费后,小时到了

Correct way to use GitSCM in declarative pipeline is在声明性管道中使用 GitSCM 的正确方法是

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

Not like I found in most places in web不像我在网络上的大多数地方找到的那样

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

Tried using尝试使用

checkout scm: [$class: 'GitSCM', 
  userRemoteConfigs: [[url: '${repoURL}']], 
  branches: [[name: 'refs/tags/${tag-version}']]],poll: false

This fails with an Authentication error.这将失败,并显示身份验证错误。 Is there any way other than using除了使用以外还有其他方法吗

withCredentials withCredentials

to checkout tag in a Jenkinsfile在Jenkinsfile中签出标签

I also have to quote the credential id我还必须引用凭据 ID

stage('checkout') {
    steps {
        checkout([$class: 'GitSCM', branches: [[name: tagVersion]],
                  userRemoteConfigs: [[url: 'ssh://git@repo',
                                       credentialsId: 'my-user-id']]
                ])
        }
    }

Annoation注释

'my-user-id' is the id of the entry you will find on the credentials page. 'my-user-id' 是您将在凭据页面上找到的条目的 ID。

But it's not the title you see in the dropdown select box in the gui.但这不是您在 gui 的下拉选择框中看到的标题。

我希望它像普通分支一样工作,您是否尝试过不使用“refs/tags/”前缀?

The authentication error has nothing to do with the tag - seems like 2 different issues.身份验证错误与标签无关 - 似乎是 2 个不同的问题。

You should add a credentialId to the userRemoteConfigs part, as such:您应该将credentialId添加到userRemoteConfigs部分,如下所示:

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

Also, you can use the following format for variables:此外,您可以对变量使用以下格式:

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

If one don't want to fiddle around with the cryptic syntax, I've been using this solution to switch to a dedicated tag or branch, especially if it's a job parameter and not clear if the given value is a branch or a tag:如果不想摆弄神秘的语法,我一直在使用此解决方案切换到专用标签或分支,特别是如果它是作业参数并且不清楚给定值是分支还是标签:

git(
    credentialsId: '<your-cred-id>',
    url: "<your-repo-url>"
)
sh(script:"""
    git checkout \$(git rev-parse --verify ${GIVEN_BRANCH_OR_TAG})
""")

The result will be in detached head mode but for most cases that's not a problem anyway.结果将处于分离头模式,但在大多数情况下,无论如何这都不是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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