-
[Jenkins] gitlab authentication error: fatal: Authentication failed for http://~CICD 2022. 2. 10. 14:54
Jenkins에서 Gitlab repo를 pull 받아와서 build 하려고 하는데 authentication error가 났다.
terminal에서 pull을 해보면 login을 하라고 나오고 해당 gitlab repo 아이디와 비밀번호를 치면 정삭적으로 pull 이 되는데 Jenkins에서 Git pull을 하면 login을 해줄 수 없기 때문에 다음과 같은 에러가 난다.
Warning: CredentialId "root" could not be found. Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- http://192.168.158.12:9000/teespace/teespace-platform.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: stdout: stderr: remote: HTTP Basic: Access denied fatal: Authentication failed for 'http://{gitlab_adress}.git/'
gitlab에서 pull을 받아 올 때 두 가지 형식의 주소 (ssh, http)로 gitlab repo에 접근 할 수 있다.
# ssh와 http 주소 예시 ssh: git@192.168.151.33:test/project.git http: http://192.168.151.:9000/test/project.git
Jenkins에서 yarn 을 이용해 빌드를 해다 보면 http 로 gitlab repo 에 접근하는 경우도 생기는데 authentication error가 생기면 해결책은 ssh 로 접근 할 때와 http 로 접근 할 때가 각각 다르다.
ssh 로 gitlab repo에 접근할 때 authentication 에러가 나는 경우
1. Jenkins 가 설치되어 있는 서버에서 "ssh-keygen" 명령어를 이용해 ssh-key를 생성해 준다.
2. 생성된 키를 "cat /root/.ssh/id_rsa.pub" 로 출력 한 후 복사한다.
3. gitlab에 생성된 ssh-key를 입력해준다.
1. ssh-keygen
root@galxay:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:keTdg5raseBcO6gxNldpfFAWuobQdMuCpb3VysUfoKs root@galaxy The key's randomart image is: +---[RSA 2048]----+ | ... . .o+| | .o.=O . .+ | | o.o*B+= o. .| | o ==o=.o.o. | | =.S+.. ++ | | o. .B .o | | . .Eo + . | | o o . o | | | +----[SHA256]-----+
2. cat /root/.ssh/id_rsa.pub
root@galaxy:~# cat /root/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAhABAAABAQDp0CgQdlmfV5n9+APfTh1MinR+OfWdi9PT77uRdWdibG8VKpbcTFM5ovXeDdHZ+4lvTWFxYCtK+28WP2EjYZZi3xVf+qoj/xG+i/6IIPB3TjGAlLuaeraTMFRAaHPeK0Cyfn+H4HDdk7XOzboDWRRr3PDcQX3ywcvr51LGOWCQL4yBxQANTMm3eTd/8o6vdzgHBBah4d2DPxFMIGLgt/2e3zFDfW34kmPhkNNXS9gH2QUOeynImJJxYwloKalBWblL422573quZW4DPivDOgwCV895FWDB9sauLvahWLDK1ej8wmaN0Q/F+Yuvvj0tkUWe/6KTORuAWiZyGTjVb061 root@galaxy
3. gitlab에 ssh-key 입력
Fig 1. gitlab에 ssh-key 입력 http 로 gitlab repo에 접근할 때 authentication 에러가 나는 경우
jenkins 서버 terminal에서 git config 명령어로 다음과 같이 gitlab ID와 email을 입력해 준다.
git config --global user.name "root" git config --global user.email abcd@gmail.com git config --global credential.helper store
'CICD' 카테고리의 다른 글