[CI/CD] Jenkins와 GitHub 연동하기

RUNGOAT·2023년 5월 26일
0

CI/CD

목록 보기
10/11
post-thumbnail

1️⃣   GitHub Repository에서 Token 발급

Settings -> Developer settings -> Personal access tokens -> Tokens (classic)

  • repo, admin:org, admin:repo_hook 을 선택
  • 발급 받은 token은 다시 볼 수 없기에 따로 저장해둔다.

2️⃣   Jenkins Plugin 설치

  • Generic Webhook Trigger Plugin
  • GitHub Integration Plugin
  • GitHub API Plugin

3️⃣   Jenkins Credentials 생성

Jenkins 관리 -> Manage Credentials

  • Username : 본인의 GitHub 아이디
  • Password : 위에서 발급 받은 GitHub token
  • ID : Credentials 이름
  • Description : Optional

4️⃣   Jenkins Pipeline 설정

{pipeline name} -> Configuration

General - GitHub project - Project url 작성

  • Project url : GitHub Repository 경로

  • Repository URL : GitHub Repository 경로.git
  • Credentials : 위에서 생성한 Credentials
  • Branch Specifier : trigger Branch
  • Script Path : 루트 프로젝트에서 Jenkinsfile의 경로

5️⃣   Jenkinsfile 작성

✅ 빌드할 directory에서 Jenkinsfile을 작성한다.
ex) 루트 프로젝트/Back-end/Jenkinsfile

pipeline {
    agent any
    
    stages {
        
        stage('github-clone') {
            steps {
                git branch: 'BE', credentialsId: 'github_token', url: '{REPOSITORY URL}'
            }
        }
        
   		// stage...
   	}
}

6️⃣   GitHub Repository Webhooks 설정

GitHub의 Repository -> Settings -> Webhooks -> Add webhook

  • Payload URL : http://Jenkins주소/github-webhook/
  • Content type : application/json

📌 참고

profile
📞피드백 너무나 환영

0개의 댓글