[英]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.