[英]Checkout from Gitlab is getting fail in Jenkins pipeline
我已閱讀了大量文檔,但無法解決此問題。
我使用下面的代碼從jenkinfile中的gitlab進行checkout
checkout changelog: true, poll: true, scm: [
$class: 'GitSCM',
branches: [[name: "origin/${env.gitlabSourceBranch}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'PreBuildMerge',
options: [
fastForwardMode: 'FF',
mergeRemote: 'origin',
mergeStrategy: 'default',
mergeTarget: "${env.gitlabTargetBranch}"
]
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'gitlab-jenkins-user-credentials',
name: 'origin',
url: "${env.gitlabSourceRepoHttpUrl}"
]]
]
我甚至試過了
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitlab-jenkins-user-credentials', url: 'http://jenkins-master/testproject/devops_artifacts/test_devops.git']]]
但我一直收到這個錯誤:
Warning: CredentialId "gitlab-jenkins-user-credentials" could not be found.
Cloning the remote Git repository
Cloning repository http://gitlab-master.com/testproject/devops_artifacts/test_devops.git
> C:\Program Files\Git\cmd\git.exe init C:\jenkins-docker\workspace\wildfly_gitlab # timeout=10
Fetching upstream changes from http://gitlab-master.com/testproject/devops_artifacts/test_devops.git
> C:\Program Files\Git\cmd\git.exe --version # timeout=10
> C:\Program Files\Git\cmd\git.exe fetch --tags --force --progress http://gitlab-master.com/testproject/devops_artifacts/test_devops.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "C:\Program Files\Git\cmd\git.exe fetch --tags --force --progress http://gitlab-master.com/testproject/devops_artifacts/test_devops.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: Logon failed, use ctrl+c to cancel basic credential prompt.
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'http://gitlab-master.com/testproject/devops_artifacts/test_devops.git/'
我已經在這個表單中設置了webhook
HTTP://用戶名:c4cc893d00cfc8865fc3@10.50.9.XXX:8080 /項目/ wildfly_gitlab
我測試了它正在工作的連接。 我也在Jenkins中配置了Gitlab
連接也正常。 我不知道為什么我仍然得到錯誤。
看起來你正在使用GitLab的憑證而不是git
credentialsId: 'gitlab-jenkins-user-credentials',
在GitLab上配置訪問令牌,並將其作為憑證添加到Jenkins上。 這個新的憑證應該用於使用git來提取代碼。
參考此內容 ,了解如何使用GitLabConnection憑證(與git憑證不同),您可以使用它來構建MR。
從鏈接:
// Reference the GitLab connection name from your Jenkins Global configuration (http://JENKINS_URL/configure, GitLab section)
properties([gitLabConnection('your-gitlab-connection-name')])
node {
checkout scm // Jenkins will clone the appropriate git branch, no env vars needed
// Further build steps happen here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.