๐Ÿค ์€์ง€log ๐Ÿค

[CI/CD study] - 9. Jenkins File ๋ณธ๋ฌธ

๐Ÿ’š DevOps

[CI/CD study] - 9. Jenkins File

Eun_zii 2022. 10. 14. 12:13
 

[CI/CD study] - 7-1. Jenkins์™€ Gitea ์—ฐ๋™ํ•˜๊ธฐ

[CI/CD study] - 6. Docker ์— Jenkins ์„ค์น˜ํ•˜๊ธฐ [CI/CD study] - 5. Docker ์„ค์น˜ [CI/CD study] - 4. EC2 ์ธ์Šคํ„ด์Šค Image ๋งŒ๋“ค๊ธฐ [CI/CD study] - 3. AWS EC2 ์ธ์Šคํ„ด์Šค JAVA์„ค์น˜ [CI/CD study] - 2. SSH Client T..

eun-jii.tistory.com

 

 

[CI/CD study] - 7-2. Jenkins์™€ Gitea ์—ฐ๋™ํ•˜๊ธฐ

[CI/CD study] - 7-1. Jenkins์™€ Gitea ์—ฐ๋™ํ•˜๊ธฐ [CI/CD study] - 6. Docker ์— Jenkins ์„ค์น˜ํ•˜๊ธฐ [CI/CD study] - 5. Docker ์„ค์น˜ [CI/CD study] - 4. EC2 ์ธ์Šคํ„ด์Šค Image ๋งŒ๋“ค๊ธฐ [CI/CD study] - 3. AWS EC2 ์ธ..

eun-jii.tistory.com

 

๐Ÿ‘ฉ‍๐Ÿ’ป ํ•„์ž๋Š” ์ง€๊ธˆ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด CI/CD ์—ฐ์Šต์ค‘ ์ธ ์ƒํ™ฉ์ด๊ณ , 

7-1 ์€ ๊ฐœ์ธ์šฉ Gitea์™€ ์—ฐ๋™,

7-2 ์€ ํ”„๋กœ์ ํŠธ์šฉ ์‚ฌ์„ค๋ง ์—ฐ๋™ ์ž…๋‹ˆ๋‹ค. ๐Ÿ‘ฉ‍๐Ÿ’ป

 

 

 

์ด์ „ ๊ธ€๋“ค์„ ์ฐธ๊ณ ํ•ด์„œ ๋”ฐ๋ผ ์˜ค์…จ๋‹ค๋ฉด ๋ช‡๊ฐ€์ง€ ์ถ”๊ฐ€ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

 

 

๋Œ€์‹œ๋ณด๋“œ โžก Jenkins ๊ด€๋ฆฌ โžก Plugin ๊ด€๋ฆฌ โžก ์„ค์น˜ ๊ฐ€๋Šฅ โžก

Multibranch Scan Webhook Trigger   ์„ค์น˜ํ•ด์ฃผ๊ธฐ

 

๋งŒ๋“ค์–ด๋‘” Multibranch pipeline repository ์ด๋ฆ„์˜† ํ™”์‚ดํ‘œ ํด๋ฆญ โžก Configure ํด๋ฆญ

 

์—ฐ๊ฒฐ ํ•ด๋‘์—ˆ๋˜ Branch Sources ์— Gitea server ์•„๋ž˜์— Behaviours ์™€ Property strategy ๋ฅผ ์‚ฌ์ง„๋Œ€๋กœ ์„ค์ •

* ์•„๋ž˜ Add ๋ฒ„ํŠผ ํด๋ฆญํ›„ Filter by name (with regular expression) ์ถ”๊ฐ€ ํ›„ " (main.*) " ์ž‘์„ฑ

 

 

 

Build Configuration์€ Jenkins-file์ด default ๊ฐ’์œผ๋กœ ๋˜์–ด์žˆ์Œ์œผ๋กœ ๊ทธ๋Œ€๋กœ ๋‘๊ณ  ๋„˜์–ด๊ฐ€๊ธฐ

 

 

๊ธ€ ๋งจ์œ„ Multibranch Scan Webhook Trigger ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ ํ–ˆ๋‹ค๋ฉด 

Scan Multibranch Pipeline Triggers ์ด ์ƒ๊ธฐ๊ณ  ๋‘˜๋‹ค ์ฒดํฌ๋ฐ•์Šค ์„ ํƒํ›„ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด ์ž‘์„ฑ

* Trigger token ์ด๋ฆ„์€ Gitea์—์„œ webhook ์„ค์ •์„ ํ•  ๋•Œ header์— ๋‹ด์„ token์„

์ง€์ •ํ•ด์ฃผ๋Š” ๊ฑฐ๊ธฐ ๋•Œ๋ฌธ์— ์ž์‹ ์ด ์›ํ•˜๋Š” ์ด๋ฆ„์œผ๋กœ ์ง€์ •ํ•ด์ฃผ๋ฉด ๋จ

 

์™ผ์ชฝ ํ•˜๋‹จ Save ํด๋ฆญ

 

๐ŸŽฃ Jenkins File ๋งŒ๋“ค๊ธฐ

 

๊ธฐ์กด Gitea ์™€ Jenkins ์—ฐ๋™๋•Œ ๋งŒ๋“ค์–ด๋‘” VSCODE ํŒŒ์ผ์—

์ƒˆํŒŒ์ผ โžก  Jenkinsfile ์„ ๋งŒ๋“ค๋ฉด ์•„์ €์”จ์–ผ๊ตด ๋ชจ์–‘์˜ ํŒŒ์ผ์ด ์ƒ์„ฑ๋จ

 

pipeline {
    agent any
      stages {
          stage('stage 1'){
              steps {
                  echo "Hello world"
              }
          }
      }
}

 

ํŒŒ์ผ์— ์œ„ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ๊ณ  push

 

 

push ํ• ๋•Œ 

โŒจ๏ธ git commit -m "second commit"

โŒจ๏ธ git add Jenkinsfile

โŒจ๏ธ git commit -m "second commit"

โŒจ๏ธ git push origin main

 

 

Gitea Repository ์— Commit ๋œ๊ฒƒ ํ™•์ธ

 

 

Jenkins ๋กœ ๋Œ์•„๊ฐ€์„œ ๋‹ค์‹œ Scan + Log ํ•ด๋ณด๊ธฐ 

 

Jenkins-file Found ์™„๋ฃŒ โญ๏ธ

 

๐ŸŽฃWephook ์„ค์ •

 

Gitea ์—์„œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ํด๋ฆญ ์šฐ์ธก์— ์„ค์ • โžก ์›นํ›… โžก webhook ์ถ”๊ฐ€ โžก Gitea ํด๋ฆญ

 

 

URL ์—๋Š” http://์  ํ‚จ์Šค์ฃผ์†Œ/multibranch-webhook-trigger/invoke?token=(Trigger token)

* (Trigger token) ์—๋Š” ์œ„์— ์„ค์ •ํ–ˆ๋˜ Scan by webhook ์˜ Trigger token ์ ์–ด์ฃผ๊ธฐ

 

Webhook ๊ฐฑ์‹ 

 

 

webhook ๊ฐฑ์‹  ๋ฐ‘

" ์ „๋‹ฌ ์‹œํ—˜ " ๋ฒ„ํŠผ์„ ํ†ตํ•ด test๋ฅผ ์ง„ํ–‰

 

์˜ค๋ฅ˜๊ฐ€ ๊ณ„์† ๋‚˜์„œ (๋ฏผ๋งํ•˜๋‹ˆ๊นŒ ์ž‘๊ฒŒ..ใ…Ž๐Ÿคฆ‍โ™€๏ธ) ์—ฌ๊ธฐ์ €๊ธฐ ๋ฌธ์˜๋“œ๋ฆฌ๋‹ค๊ฐ€

Gitea ์‚ฌ์„ค๋ง์„ ์ด์šฉ์ค‘์ธ ์ƒํƒœ๋ผ EC2์—์„œ ์ธ๋ฐ”์šด๋“œ๊ทœ์น™ ์—์„œ ํฌํŠธ ๋ฅผ Public์œผ๋กœ ์—ด์–ด์ฃผ๋‹ˆ๊นŒ ๋ฐ”๋กœ ์›นํ›… ์„ฑ๊ณตใ…Ž

 

์›นํ›… ์„ฑ๊ณต โญ๏ธ

 

+ ์ถ”๊ฐ€๋กœ

 

์ฝ”๋“œ ์ž‘์„ฑํ›„ Gitea ์— ์ปค๋ฐ‹ ํ–ˆ์„๋•Œ

Jenkins ์—์„œ ๋นŒ๋“œ ๊ฐ€ ์ž‘๋™ํ•˜๋Š”๊ฒƒ์„ ํ™•์ธ ํ• ์ˆ˜ ์žˆ๋‹ค

 

 

โค๏ธ ๋„์›€์ฃผ์‹ ๋ถ„ : 

https://0andwild.tistory.com/28

728x90