DevOps/Jenkins

[Jenkins] CI

잔망루피 2024. 4. 21. 00:38

1. Jenkins 관리 > Plugins > Available plugins에서 GitLab을 검색해서 설치 

 

2. Jenkins 관리 > SystemGitLab 설정

  • 발급받은 GitLab API token을 넣는다.
  • Credentials를 추가 후 목록에서 선택까지 해줘야 한다.
  • Test connection이 success로 뜨면 성공이다.

Credentials > Add > Jenkins

 

 

3. Jenkins 관리 > CredentialsGitLab 아이디, 비밀번호 등록

  • Username: GitLab 아이디
  • Password: GitLab 비밀번호
  • ID: 스크립트 작성할 때 credentialsId

 

 

4. Pipeline 스크립트 작성

  • 입력한 레포지토리의 develop-music 브랜치에서 credentailsId로 등록된 정보를 이용하여 클론 받기
  • root 디렉토리 아래에 있는 back 폴더에서 빌드
pipeline {
    agent any
    
    stages {
        stage('clone') { 
            steps {
                git branch: 'develop-music', credentialsId: '{등록한 credentail id 입력}', url: '{레포지토리 주소 입력}'}
        }
    
        stage('build') { 
             steps {
                dir("./back") {
                     script {
                        sh "chmod +x gradlew"
                        sh "./gradlew build --info"
                    }
                }
            }
        }
        
    }
}

 

 

 


🐛 에러

첫 번째 상황

  • token 권한 다 허용해줬는데 그냥 token으로 등록된 credentials 자체를 인식못함
Started by user throwSong
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/CI_music
[Pipeline] {
[Pipeline] stage
[Pipeline] { (clone)
[Pipeline] git
The recommended git tool is: NONE
Warning: CredentialId "gitlab_api_token" could not be found.
 > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/CI_music/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url {git url} # timeout=10
Fetching upstream changes from {git url}
 > git --version # timeout=10
 > git --version # 'git version 2.25.1'
 > git fetch --tags --force --progress -- {git url} +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from {git url}
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1241)
	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1305)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:136)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:101)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:88)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- {git url} +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://lab.ssafy.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied
fatal: Authentication failed for '{git url}'

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2846)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2185)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:635)
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:997)
	... 11 more
ERROR: Error fetching remote repo 'origin'
ERROR: Maximum checkout retry attempts reached, aborting
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (build)
Stage "build" skipped due to earlier failure(s)
[Pipeline] getContext
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

 

 

두 번째 상황

  • GitLab 아이디, 비밀번호를 사용했는데 결국은 비밀번호가 잘못됨 😂
Started by user throwSong
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/CI_music
[Pipeline] {
[Pipeline] stage
[Pipeline] { (clone)
[Pipeline] git
The recommended git tool is: NONE
using credential gitlab_mj
 > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/CI_music/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url {git url} # timeout=10
Fetching upstream changes from {git url}
 > git --version # timeout=10
 > git --version # 'git version 2.25.1'
using GIT_ASKPASS to set credentials 
 > git fetch --tags --force --progress -- {git url} +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from {git url}
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1241)
	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1305)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:136)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:101)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:88)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- {git url} +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://lab.ssafy.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied
fatal: Authentication failed for '{git url}'

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2846)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2185)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:635)
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:997)
	... 11 more
ERROR: Error fetching remote repo 'origin'
ERROR: Maximum checkout retry attempts reached, aborting
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (build)
Stage "build" skipped due to earlier failure(s)
[Pipeline] getContext
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE
반응형

'DevOps > Jenkins' 카테고리의 다른 글

젠킨스 설치  (0) 2024.04.19
Jenkins와 GitLab 연동  (0) 2024.03.17
Jenkins 플러그인 설치 에러  (0) 2024.03.12