[英]Checkout a tag in Jenkins pipeline
嘗試使用
checkout scm: [$class: 'GitSCM',
userRemoteConfigs: [[url: '${repoURL}']],
branches: [[name: 'refs/tags/${tag-version}']]],poll: false
這會因身份驗證錯誤而失敗。 除了使用還有什么辦法
有憑證
在 Jenkinsfile 中簽出標簽
消費后,小時到了
在聲明性管道中使用 GitSCM 的正確方法是
checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: repoURL, credentialsId: credential]], branches: [[name: tag-version]]],poll: false
不像我在網絡上的大多數地方找到的那樣
checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: repoURL], [credentialsId: credential]], branches: [[name: tag-version]]],poll: false
嘗試使用
checkout scm: [$class: 'GitSCM',
userRemoteConfigs: [[url: '${repoURL}']],
branches: [[name: 'refs/tags/${tag-version}']]],poll: false
這將失敗,並顯示身份驗證錯誤。 除了使用以外還有其他方法嗎
withCredentials
在Jenkinsfile中簽出標簽
我還必須引用憑據 ID
stage('checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: tagVersion]],
userRemoteConfigs: [[url: 'ssh://git@repo',
credentialsId: 'my-user-id']]
])
}
}
注釋
'my-user-id' 是您將在憑據頁面上找到的條目的 ID。
但這不是您在 gui 的下拉選擇框中看到的標題。
我希望它像普通分支一樣工作,您是否嘗試過不使用“refs/tags/”前綴?
身份驗證錯誤與標簽無關 - 似乎是 2 個不同的問題。
您應該將credentialId
添加到userRemoteConfigs
部分,如下所示:
checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: '${repoURL}'], [credentialsId: '${credential}']], branches: [[name: '${tag-version}']]],poll: false
此外,您可以對變量使用以下格式:
checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: repoURL], [credentialsId: credential]], branches: [[name: tag-version]]],poll: false
如果不想擺弄神秘的語法,我一直在使用此解決方案切換到專用標簽或分支,特別是如果它是作業參數並且不清楚給定值是分支還是標簽:
git(
credentialsId: '<your-cred-id>',
url: "<your-repo-url>"
)
sh(script:"""
git checkout \$(git rev-parse --verify ${GIVEN_BRANCH_OR_TAG})
""")
結果將處於分離頭模式,但在大多數情況下,無論如何這都不是問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.