我的gitlab项目管道的身份验证问题



我的jenkins有多分支选项,我有一个Gitlab身份验证问题。这是我的詹金斯文件:

pipeline {
agent any 
environment {
registry = "*****@gmail.com/test"
registryCredential = 'test'
dockerImage = ''
}
stages {
stage('Cloning our Git') {
steps{
git 'https://gitlab.com/**********/*************/************.git'
}
}
stage('Build docker image') {
steps {  
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER"
}
}
}
stage('Deploy our image') {
steps{
script {
docker.withRegistry( '', registryCredential ){
dockerImage.push()
}
}
}
}
stage('Cleaning up') {
steps{
sh "docker rmi $registry:$BUILD_NUMBER"
}
}
}
}

这是我得到的错误:引起原因:hudson.plugins.git.git异常:命令"git fetch--tags--force--progress--https://gitlab.com/************/*******/***************.git+refs/heads/:refs/remotes/origin/";返回的状态代码128:标准输出:stderr:remote:HTTP Basic:访问被拒绝。提供的密码或令牌不正确,或者您的帐户已启用2FA,您必须使用个人访问令牌而不是密码。看见https://gitlab.com/help/topics/git/troubleshooting_git#error-关于gitfetchhttp基本访问被拒绝

我想知道如何使用jenkinsfile向gitlab进行身份验证,或者如果你有更好的解决方案,我很感兴趣。感谢

如果您按照错误消息中提供的链接进行操作,则会出现以下情况:https://docs.gitlab.com/ee/user/profile/account/two_factor_authentication.html#troubleshooting

您需要创建一个个人访问令牌,这是一种特殊的ID,用于委托访问您的部分帐户权限。

PAT的文档如下:https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html

在Gitlab存储库界面中,它位于Settings > Access Tokens下。

当您尝试读取HTTPS存储库时,似乎需要创建一个权限为read_repository的令牌。

然后,您应该能够使用以下内容访问存储库:https://<my-user-id>:<my-pat>@gitlab.com/<my-account>/<my-project-name>.git

最新更新