簡體   English   中英

我的管道與我的 gitlab 項目的身份驗證問題

[英]Authentication problem of my pipeline with my gitlab project

我的 jenkins 處於多分支選項中,但我遇到了對 Gitlab 的身份驗證問題。 這是我的 jenkins 文件:

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.GitException: Command "git fetch --tags --force --progress -- https://gitlab.com/********* ***/*******/***************.git +refs/heads/ :refs/remotes/origin/ " 返回狀態碼 128: stdout: stderr :遠程:HTTP 基本:訪問被拒絕。 提供的密碼或令牌不正確,或者您的帳戶啟用了 2FA,您必須使用個人訪問令牌而不是密碼。 https://gitlab.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied

我想知道如何使用 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM