0

I am in multi-branch option with my jenkins and I have a problem of authentication to Gitlab. Here is my jenkins file :

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"
            }
        }
    }
}

This is the error I got: Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- https://gitlab.com/************/*******/***************.git +refs/heads/:refs/remotes/origin/" returned status code 128: stdout: stderr: remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See https://gitlab.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied

I would like to know how to authenticate with the jenkinsfile to gitlab or if you have a better solution for me I am interested. Thanks

1 Answer 1

1

If you follow the link provided in the error message, you end up here: https://docs.gitlab.com/ee/user/profile/account/two_factor_authentication.html#troubleshooting

You need to create a Personal Access Token which is kind of a special ID to delegate access to parts of your account rights.

The documentation for PAT is here: https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html

In the Gitlab repository interface, it is under Settings > Access Tokens.

As you try to read an HTTPS repository, it seems you need to create a token with rights read_repository.

Then you should be able to access the repository with: https://<my-user-id>:<my-pat>@gitlab.com/<my-account>/<my-project-name>.git

Sign up to request clarification or add additional context in comments.

1 Comment

You can also create username-password-credential and useit (remember: username == GitlabUserId and password == access-token)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.