[CI/CD] Jenkins์™€ Gitea ์—ฐ๋™

2023. 6. 1. 19:31ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•

 

 

 

 

 

 

์  ํ‚จ์Šค ๋งˆ์Šคํ„ฐ

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."




 

 

 

 

 

 

 

๐Ÿ—‚ ๋ชฉ์ฐจ

โš ๏ธ ์•„๋ž˜ ๋ชฉ์ฐจ ์ค‘ ๋ช‡๋ช‡๊ฐœ์˜ ๋งํฌ๊ฐ€ ๊ฑธ๋ฆฌ์ง€ ์•Š๋Š” ๋ฌธ์ œ๋กœ ๊ธ€ ๋งจ ํ•˜๋‹จ์— ๋‹ค์Œ ๊ธ€๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ๋‘์—ˆ์Šต๋‹ˆ๋‹ค.

โœ… [CI/CD] Jenkins์™€ Gitea ์—ฐ๋™
โœ… [CI/CD] Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ
โœ… [CI/CD] ์ •์  ์ฝ”๋“œ ๋ถ„์„ ํˆด SonarQube์™€ Jenkins ์—ฐ๋™
โœ… [CI/CD] SonarQube๋ฅผ ํ†ตํ•ด Code Convention ์ ์šฉ
โœ… [DevOps] JAVA Gradle JaCoCo (Code coverage) ์„ค์ •ํ•˜๊ธฐ 
โœ… [DevOps] JAVA Gradle JaCoCo (Code coverage) ์„ค์ •ํ•˜๊ธฐ (์ถ”๊ฐ€)(https://junyharang.tistory.com/392)

โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘  Application Linuxt(Ubuntu)์— SSH๋ฅผ ์ด์šฉํ•œ ํŒŒ์ผ ์ „์†ก
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ก Create Docker Image And BackUp
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘  Application ๋„์ปค ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ก Application Docker Run)(https://junyharang.tistory.com/406)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ข Application Docker Health Check)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘  NGINX ๊ฐ ์ข… ์„ค์ •) 
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ก NGINX Docker ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ) 
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ข NGINX Docker Run & Health Check)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ข NGINX ์žฌ ์„ค์ •)



๐Ÿค” ๋‚ด๊ฐ€ ๋งŒ๋‚œ ๋ฌธ์ œ

โ›”๏ธ [Jenkins] java.lang.OutOfMemoryError: Java heap space

 

 

 

 

๐Ÿš€ Jenkins์™€ Gitea๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ CI/CD

    ๐Ÿ”ฝ  ๊ฐœ์š”

        ๐Ÿ“ฆ ๊ตฌ์„ฑ๋„

CI/CD ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ๊ตฌ์„ฑ๋„

 

 

 

 

 

deploy Directory Path

 

        ๐Ÿ“ฆ ์†Œ๊ฐœ


์•ˆ๋…•ํ•˜์„ธ์š”?

์˜ค๋Š˜์€ Jenkins์™€ Gitea๋ฅผ ์—ฐ๊ฒฐํ•˜์—ฌ CI/CD ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ง„ํ–‰ํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.

์ฃผ๋‹ˆ๋Š” Git Hub์ด๋‚˜, Git Lab์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , ๋‚ด๋ถ€ ์„œ๋ฒ„์— Gitea๋ฅผ ๊ตฌ์„ฑํ–ˆ๊ณ , ๊ทธ ๊ณณ์„ ํ†ตํ•ด ํ˜•์ƒ ๊ด€๋ฆฌ๋ฅผ ํ•˜๊ณ  ์žˆ์–ด์š”.

์ฃผ๋‹ˆ๊ฐ€ ๋งŒ๋“  Gitea ์„ค์น˜ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ๋Š” ์ด ๊ณณ์— ์ค€๋น„ํ•ด ๋‘์—ˆ์–ด์š”.

 

[Synology NAS] ๋‚˜๋งŒ์˜ GitHub ๋งŒ๋“ค๊ธฐ - Git Server์™€ Gitea ์„ค์น˜

๐Ÿ—‚ ๋ชฉ์ฐจ โ— [Synology NAS] ๋‚˜๋งŒ์˜ GitHub ๋งŒ๋“ค๊ธฐ - Git Server์™€ Gitea ์„ค์น˜ โ— [Synology NAS] ๋‚˜๋งŒ์˜ Jenkins ๋งŒ๋“ค๊ธฐ ์‹œ๋†€๋กœ์ง€ Synology DS218 2BAY NAS ๊ณต์‹ํŒ๋งค์  COUPANG www.coupang.com "์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™

junyharang.tistory.com


๊ทธ๋ฆฌ๊ณ , Jenkins๋„ ์„ค์น˜ํ•ด ์ฃผ์–ด์•ผ ํ•˜๋Š”๋ฐ, ์ฃผ๋‹ˆ๋Š” Docker๋ฅผ ์ด์šฉํ•ด์„œ Jenkins๋ฅผ ๊ตฌ์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.

์ด ์—ญ์‹œ ์„ค์น˜ ๋ฐฉ๋ฒ•์€ ์ด ๊ณณ์— ์ค€๋น„ํ•ด ๋‘์—ˆ์–ด์š”.

 

[๊ฐ€์ƒํ™” - Container] Docker๋ฅผ ์ด์šฉํ•œ Jenkins ์„ค์น˜

์  ํ‚จ์Šค ๋งˆ์Šคํ„ฐ COUPANG www.coupang.com "์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค." ๐Ÿš€ Docker๋ฅผ ์ด์šฉํ•œ Jenkins ์„ค์น˜ ๐Ÿ”ฝ Ubuntu 22.04.05 LTS Server ๐Ÿ“ฆ Jenkins ์„ค

junyharang.tistory.com

 

 

    ๐Ÿ”ฝ  Jenkins ๊ตฌ์„ฑ

        ๐Ÿ“ฆ Gitea ์—ฐ๊ฒฐ

์ตœ์ดˆ Jenkins์™€ Gitea์™€ ์—ฐ๊ฒฐํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.


Jenkins ๊ด€๋ฆฌ -> PlugIn Manager


๊ตฌ์„ฑ์„ ํ•˜๊ธฐ ์ „ Gitea์™€ ์—ฐ๊ฒฐ์„ ์œ„ํ•ด PlugIn์„ ์„ค์น˜ํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.
์œ„์™€ ๊ฐ™์ด Gitea PlugIn์„ ๋ฐ›์•„ ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.


Jenkins ๊ด€๋ฆฌ -> ์‹œ์Šคํ…œ ์„ค์ •


์ด๋ฒˆ์—๋Š” ์‹œ์Šคํ…œ ์„ค์ •์œผ๋กœ ๋“ค์–ด๊ฐ€์„œ Gitea ์—ฐ๊ฒฐ ์ž‘์—…์„ ํ•ด ์ค„๊ฒŒ์š”.

Jenkins ๊ด€๋ฆฌ Configure System -> Gitea Servers


์œ„์™€ ๊ฐ™์ด Gitea ์ด๋ฆ„์„ Name์— ์ง€์ •ํ•ด ์ฃผ๊ณ , Gitea IP ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด ์ค๋‹ˆ๋‹ค.


๊ทธ๋Ÿฐ ๋’ค Add๋ฅผ ๋ˆŒ๋Ÿฌ Credentials๋ฅผ ๋“ฑ๋กํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.


Gitea -> ์„ค์ • -> ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜


Credentials ๋“ฑ๋ก์„ ์œ„ํ•ด Gitea์—์„œ Access Token ๊ฐ’์„ ๋งŒ๋“ค์–ด ์ฃผ๋ ค๊ณ  ํ•ด์š”.





Token ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ , ์ƒ์„ฑ์„ ๋ˆ„๋ฅด๋ฉด ์œ„์™€ ๊ฐ™์ด Access Token์ด ๋ฐœ๊ธ‰๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ด ๊ฐ’์„ ๋ณต์‚ฌํ•˜์—ฌ Jenkins์— ๋„ฃ์–ด์ค„๊ฑฐ์—์š”.



Jenkins์—์„œ ์œ„์™€ ๊ฐ™์ด Kind ๋ถ€๋ถ„์— Gitea Personal Access Token์„ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.



Token์—๋Š” Gitea์—์„œ ๋ฐœ๊ธ‰ ๋ฐ›์€ Access Token ๊ฐ’์„ ์ž…๋ ฅํ•ด ์ค๋‹ˆ๋‹ค.
ID ๋ถ€๋ถ„์€ ํ•ด๋‹น Credentials์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•ด ์ฃผ๋Š” ๊ณณ์ด๊ณ , Description์€ ํ•ด๋‹น Credentials์— ๋Œ€ํ•œ
์ƒ์„ธ ๋‚ด์šฉ์„ ์ž…๋ ฅํ•ด ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ ๋’ค Add๋ฅผ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.



Credentials์— ์œ„์—์„œ ๋งŒ๋“  ID๋ฅผ ์ฐพ์•„ ์„ ํƒ์„ ํ•ด์ฃผ๋ฉด ์œ„์™€ ๊ฐ™์ด Gitea Version์ด ๋‚˜์˜ค๊ฒŒ ๋˜์š”.
๋งŒ์•ฝ Version์ด ๋‚˜์˜ค์ง€ ์•Š๋Š”๋‹ค๋ฉด Network ์—ฐ๊ฒฐ์ด ๋˜์ง€ ์•Š๊ฑฐ๋‚˜, Access Token์ด ์ œ๋Œ€๋กœ ์„ค์ •๋˜์ง€ ์•Š์€ ๊ฑฐ์—์š”.

์œ„์™€ ๊ฐ™์ด ๋˜์—ˆ๋‹ค๋ฉด ์ œ์ผ ๋ฐ‘์— ์ €์žฅ ํ˜น์€ Save๋ฅผ ๋ˆŒ๋Ÿฌ ์„ค์ •์ฐฝ์„ ๋‚˜๊ฐ€ ์ค๋‹ˆ๋‹ค.


๋ฐ˜์‘ํ˜•




        ๐Ÿ“ฆ Multibranch Pipeline Job ๊ตฌ์„ฑ

์ด์ œ Jenkins์— Multibranch Pipeline Job์„ ๋งŒ๋“ค์–ด ๋ณด๋ ค๊ณ  ํ•ด์š”.
Multibranch Pipeline์€ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์— Server์™€ ์šด์˜ ํ™˜๊ฒฝ์— Server๊ฐ€ ๊ฐ๊ฐ ๋‹ค๋ฅผ ๋•Œ, ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ฃผ๋‹ˆ๋Š” ๋‘ ์„œ๋ฒ„ ํ™˜๊ฒฝ์„ ๋‹ค๋ฅด๊ฒŒ ๊ตฌ์„ฑํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์€ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์— ๋งž๋Š” Server์— ์šด์˜ ํ™˜๊ฒฝ์€ ์šด์˜ ํ™˜๊ฒฝ์— ๋งž๋Š” Server์— Application์ด ์˜ฌ๋ผ๊ฐˆ ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์„ฑํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.


Jenkins ๊ด€๋ฆฌ -> PlugIn Manager


์ตœ์ดˆ ์œ„์™€ ๊ฐ™์ด Multibranch Scen Webhook Trigger PlugIn์„ ์„ค์น˜ํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.




Jenkins Main ํ™”๋ฉด ์™ผ์ชฝ์— ์ƒˆ๋กœ์šด Item์„ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.



์ด ๊ณณ์—์„œ Enter an Item name์— ํ•ด๋‹น Job ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด ์ฃผ๊ณ , Multibranch Pipeline์„ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.

๊ทธ๋ฆฌ๊ณ , ๋ฐ‘์— OK๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



์œ„์™€ ๊ฐ™์ด ์„ค์ •์ฐฝ์ด ๋‚˜์˜ค๋ฉด Gitea์™€ Webhook ์—ฐ๊ฒฐ์„ ์œ„ํ•œ ์„ค์ •์„ ํ•ด ์ค„ ์ˆ˜ ์žˆ์–ด์š”.


Display Name


์ตœ์ดˆ ํ•ด๋‹น Job์— ์ด๋ฆ„์„ ์ง€์ •ํ•ด ์ค๋‹ˆ๋‹ค.


์ตœ์ดˆ Branch Sources์—์„œ ์œ„์™€ ๊ฐ™์ด Gitea๋ฅผ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.


์ตœ์ดˆ ์ด ๊ณณ์—์„œ ์ด ์ „์— Gitea ์—ฐ๊ฒฐ์„ ์œ„ํ•ด ์„ค์ •ํ–ˆ๋˜ ๊ฐ’๋“ค์„ ์„ ํƒํ•ด ์ฃผ๋ฉด ๋œ๋‹ต๋‹ˆ๋‹ค.

๋‹ค๋งŒ Credentials ๋ถ€๋ถ„์—๋Š” ์—ฐ๊ฒฐํ•˜๊ณ ์ž ํ•˜๋Š” Repository๊ฐ€ Public์ด๋ผ๋ฉด ์ž…๋ ฅํ•˜์ง€ ์•Š์•„๋„ ๋˜์ง€๋งŒ,
Private์ด๋ผ๋ฉด ๋ฐ˜๋“œ์‹œ ์ž…๋ ฅํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.



ํ˜„์žฌ Jenkins์™€ Gitea๊ฐ€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋Š” ์ƒํƒœ ์ด๊ธฐ ๋•Œ๋ฌธ์— Owner์— ์—ฐ๊ฒฐํ•˜๊ณ ์ž ํ•˜๋Š” Repository ์†Œ์œ ์ž์˜ Gitea ID(Username)์„ ๋„ฃ์–ด์ฃผ๋ฉด Respository ๋ถ€๋ถ„์— ํ•ด๋‹น ์†Œ์œ ์ž๊ฐ€ ์†Œ์œ ํ•˜๊ณ  ์žˆ๋Š” Repository ๋ชฉ๋ก์ด ๋‚˜ํƒ€๋‚ ๊ฑฐ์—์š”.

์•Œ ๋งž๋Š” ๊ฒƒ์„ ์„คํƒํ•ด ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 


Discovery branches์˜ Strategy๋Š” ์—ฌ๋Ÿฌ ํ•ญ๋ชฉ์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ข…      ๋ฅ˜ ์ƒ ์„ธ ๋‚ด ์šฉ
only branches that are not also filed as PRs Pull Request๋กœ ์ œ์ถœ๋˜์ง€ ์•Š์€ Branch๋งŒ Trigger
only branches that are also filed as PRs Pull Request๋กœ ์ œ์ถœ๋œ Branch๋งŒ Trigger
All branches ๋ชจ๋“  Branche Trigger
Only branches that are also filed as PRs or master / main branch Pull Request๋กœ ์ œ์ถœ๋œ Branch ๋˜๋Š”
Master / Main Branche๋งŒ Trigger


๋ชจ๋“  Branch์— Trigger๋ฅผ ๊ฑธ๊ฒŒ ๋˜๋ฉด Jenkins๋Š” ์ •์‹ ์—†์ด ์ผํ•˜๊ฒŒ ๋  ๊ฑฐ๊ณ , ์„œ๋ฒ„ ์ž์›๋„ ๋‚ญ๋น„๋˜๋Š” ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ ๊ฑฐ์—์š”.

์ฃผ๋‹ˆ๋Š” Only branches that are also filed as PRs or master / main branch ๋ฅผ ์„ ํƒํ•˜์—ฌ ๊ตฌ์„ฑํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.


Discover pull requests from forks Strategy


์ด ๊ณณ์—์„œ๋Š” ํ’€ ์š”์ฒญ์ด ์–ด๋–ป๊ฒŒ ๋ฐœ๊ฒฌ๋˜๋Š”์ง€ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ข…      ๋ฅ˜ ์ƒ ์„ธ ๋‚ด ์šฉ
Merging the pull request with the current target branch revision ๋Œ€์ƒ Branche์˜ ํ˜„์žฌ ๋‚ด์šฉ๊ณผ ๋ณ‘ํ•ฉ ๋œ ๊ฒฐ๊ณผ์— ํ•ด๋‹นํ•˜๋Š” ๋ฐœ๊ฒฌ ๋œ ์ˆ˜์ • ์‚ฌํ•ญ์—์„œ ๊ฐ Pull Request๋ฅผ ๋ฐœ๊ฒฌํ•˜์—ฌ ๋™์ž‘
The current pull request revision ๊ฐ Pull Requtest๋ฅผ ํ•œ ๋ฒˆ์”ฉ ๋ฐœ๊ฒฌํ•˜๊ณ  ๋ณ‘ํ•ฉํ•˜์ง€ ์•Š๊ณ , Pull Requtest Head ๋ฆฌ๋น„์ „์— ํ•ด๋‹นํ•˜๋Š” ๋ฆฌ๋น„์ „ ๊ฒ€์ƒ‰
Both the current pull request revision and the pull request
merged with the current target branch revision
๊ฐ Pull Request์„ ๋‘ ๋ฒˆ ๊ฒ€์ƒ‰.
์ฒซ ๋ฒˆ์งธ๋กœ ๋ฐœ๊ฒฌ๋œ ์ˆ˜์ • ์‚ฌํ•ญ์€ ๊ฐ ๊ฒ€์ƒ‰์—์„œ ๋Œ€์ƒ ๋ถ„๊ธฐ์˜
ํ˜„์žฌ ๊ฐœ์ •ํŒ๊ณผ ๋ณ‘ํ•ฉํ•œ ๊ฒฐ๊ณผ์— ํ•ด๋‹น.
๋‘ ๋ฒˆ์งธ ๋ณ‘๋ ฌ๋กœ ๋ฐœ๊ฒฌ๋œ ๋ฆฌ๋น„์ „์€ ๋ณ‘ํ•ฉํ•˜์ง€ ์•Š๊ณ  ํ’€ ์š”์ฒญ ํ—ค๋“œ ๋ฆฌ๋น„์ „์— ํ•ด๋‹น.


์ฃผ๋‹ˆ๋Š” Merging the pull request with the current target branch revision ์‚ฌ์šฉํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.


Discover pull requests from forks Trust


Repository์— ๋Œ€ํ•œ ์ฝ๊ธฐ ์•ก์„ธ์Šค ๊ถŒํ•œ์„ ๊ฐ€์ง„ ๋ชจ๋“  ์‚ฌ์šฉ์ž๊ฐ€ Repository๋ฅผ ํฌํฌํ•˜๊ณ , ์ž์‹ ์˜ ํฌํฌ์— ๋ช‡ ๊ฐ€์ง€ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ ์šฉํ•œ ๋‹ค์Œ, ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์žˆ๋Š” ์›๋ž˜ Repository์— ๋Œ€ํ•ด Pull Request๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด์š”.
์ด ๊ณณ์—๋Š” ์†Œ์Šค ์ฝ”๋“œ ์ œ์–ด์— ์ €์žฅ๋œ ์ค‘์š”ํ•œ ํŒŒ์ผ์ด ์žˆ์„ ๊ฑฐ์—์š”. ์˜ˆ๋ฅผ ๋“ค์–ด Jenkins ํŒŒ์ผ์—๋Š” ์•…์˜์ ์ธ ๊บผ๋‚ด๊ธฐ ์š”์ฒญ์„ ์™„ํ™”ํ•˜๊ธฐ ์œ„ํ•ด ์ƒŒ๋“œ๋ฐ•์Šค ๊บผ๋‚ด๊ธฐ ์š”์ฒญ์— ๋Œ€ํ•œ ๊ตฌ์„ฑ ์„ธ๋ถ€ ์ •๋ณด๊ฐ€ ํฌํ•จ๋  ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค. Jenkins ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์—ฌ ๋ณดํ˜ธ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ์•…์˜์ ์ธ ๊บผ๋‚ด๊ธฐ ์š”์ฒญ ์ž์ฒด๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๊ธฐ ์œ„ํ•ด ํฌํฌ์—์„œ ๊บผ๋‚ด๊ธฐ ์š”์ฒญ์— ๋Œ€ํ•œ ์‹ ๋ขฐ ์ •์ฑ…์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์ด ์ด ๋ถ€๋ถ„์ด์—์š”.

์ข…      ๋ฅ˜ ์ƒ ์„ธ ๋‚ด ์šฉ
Nobody ํฌํฌ์—์„œ Pull Request๋Š” ๋ชจ๋‘ ๋น„ ์‹ ๋ขฐ ์ฒ˜๋ฆฌ.
์ฆ‰, Jenkins๊ฐ€ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ํŒŒ์ผ(์˜ˆ: Jenkins ํŒŒ์ผ)์„ ์š”๊ตฌํ•˜๋Š” ๊ฒฝ์šฐ ํ•ด๋‹น ํŒŒ์ผ์˜ ๋‚ด์šฉ์ด ํฌํฌ
Repository์˜ Pull Request ๋ถ„๊ธฐ๊ฐ€ ์•„๋‹Œ Origin Repository์˜ ๋Œ€์ƒ ๋ถ„๊ธฐ์—์„œ ๊ฒ€์ƒ‰.
Contributors ๊ณต๋™์ž‘์—…์ž์—์„œ Origin Repository๋กœ Pull Request๋Š” ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜๊ณ , ํฌํฌ Repository์˜ ๋‹ค๋ฅธ ๋ชจ๋“  Pull Request๋Š” ์‹ ๋ขฐํ•  ์ˆ˜ ์—†๋Š” ๊ฒƒ์œผ๋กœ ์ฒ˜๋ฆฌ. Jenkins๊ฐ€ ์ €์žฅ์†Œ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ๋ฐ, ์‚ฌ์šฉํ•œ ์ž๊ฒฉ ์ฆ๋ช…์— Origin Repository์— ๋Œ€ํ•œ ๊ธฐ์—ฌ์ž ๋ชฉ๋ก์„ Query ํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์ด ์—†๋Š” ๊ฒฝ์šฐ Origin ๊ณ„์ •๋งŒ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ์ฒ˜๋ฆฌ. ์ฆ‰, 'Nobody' ์„ค์ •๊ณผ ๊ฐ™์ด ๋ฐ˜ํ™˜.
Everyone ํฌํฌ์˜ ๋ชจ๋“  Pull Request๋Š” ์‹ ๋ขฐํ•  ์ˆ˜์žˆ๋Š” ๊ฒƒ์œผ๋กœ ์ทจ๊ธ‰
์ฃผ์˜: ์ด ์˜ต์…˜์€ ์™ธ๋ถ€ ๊ฐ€์ž…์„ ํ—ˆ์šฉํ•˜๋Š” Gitea์—์„œ ํ˜ธ์ŠคํŒ… ๋œ ๊ณต๊ฐœ ์ €์žฅ์†Œ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์œ„ํ—˜.


์ด ๋ถ€๋ถ„์—์„œ๋Š” ์ฃผ๋‹ˆ๋Š” Everyone์„ ์„ ํƒํ•ด ์ฃผ๋ ค๊ณ  ํ•ด์š”.

์ฃผ๋‹ˆ๊ฐ€ ํ˜„์žฌ ๊ตฌ์„ฑํ•œ Gitea๋Š” ๋‚ด๋ถ€ ์„œ๋ฒ„์—์„œ ๊ตฌํ˜„์ด ๋˜์–ด ์žˆ๊ณ , ์™ธ๋ถ€์—์„œ๋Š” VPN ์—ฐ๊ฒฐ์ด ์—†๋‹ค๋ฉด ์ ‘์†ํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.

 


๊ทธ๋Ÿฐ ๋’ค ์œ„์™€ ๊ฐ™์ด Add ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ Filter by name (with regular expression)์„ ์„ ํƒํ•ด ํ™œ์„ฑํ™” ํ•ด ์ค„๊ฒŒ์š”.

์ด ๋ถ€๋ถ„์€ Discover์—์„œ ์„ ํƒํ•œ Branch ์ „๋žต ์ค‘ ์ •๊ทœ ํ‘œํ˜„์‹(Regualr)์„ ์‚ฌ์šฉํ•˜์—ฌ CI/CD๋ฅผ ์œ ๋ฐœํ•  Trigger ๋Œ€์ƒ์— ํฌํ•จํ•  Branch๋ฅผ ๋‹ค์‹œ ์ •ํ•˜๋Š” ๋ถ€๋ถ„์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์–ด์š”.


์ฃผ๋‹ˆ๋Š” ์œ„์™€ ๊ฐ™์ด ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์šฉ Branch dev์™€ ์šด์˜ ํ™˜๊ฒฝ์šฉ Branch Master๋ฅผ ์„ค์ •ํ•ด ์ค„๊ฑฐ์—์š”.

์ด ๊ณณ์— ์ž…๋ ฅ๋˜์ง€ ์•Š์€ Branch๋Š” CI/CD Trigger๊ฐ€ ๋ฐœ๋™๋˜์ง€ ์•Š์•„์š”.



์ด๋ฒˆ์—๋Š” ์œ„์™€ ๊ฐ™์ด Filter by name (with wildcards)๋ฅผ ํ™œ์„ฑํ™” ํ•ด ์ค„๊ฒŒ์š”.

์ด ๋ถ€๋ถ„์€ Discover ์ „๋žต์— ํ•ด๋‹น๋˜๋Š” Branch ์ค‘ *์œผ๋กœ ๋Œ€์ƒ์— ํฌํ•จํ•  Branch๋ฅผ ๋‹ค์‹œ ์„ ์ •ํ•ด ์ฃผ๋Š” ๊ณณ์ด์—์š”.
Filter by name์€ ํ•˜๋‚˜๋งŒ ์ •ํ•ด์„œ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์ด ํ˜ผ๋ž€์Šค๋Ÿฝ์ง€ ์•Š์„๊ฑฐ์—์š”.


์ด ๊ณณ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์šฉ Branch์™€ ์šด์˜ ํ™˜๊ฒฝ์šฉ Branch๋งŒ Trigger๊ฐ€ ๋ฐœ๋™ ๋˜๋„๋ก ์„ค์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.
Exclude์— ํŠน์ • Branch ์ด๋ฆ„์„ ๋„ฃ๊ฒŒ ๋˜๋ฉด ํ•ด๋‹น Branch๋Š” Trigger๊ฐ€ ๋ฐœ๋™๋˜์ง€ ์•Š๊ฒŒ ๋ง‰์„ ์ˆ˜ ์žˆ์–ด์š”.


Build Configuration


์ด ๊ณณ Build ์„ค์ • ๋ถ€๋ถ„์€ jenkins File์„ ์ฝ์„ ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•ด ์ฃผ๋Š” ๋ถ€๋ถ„์ด์—์š”.
์ฃผ๋‹ˆ๋Š” ์†Œ์Šค ์ฝ”๋“œ ๋‚ด์— jenkins File์„ ๋‘˜ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ์œ„์น˜๋ฅผ ์œ„์™€ ๊ฐ™์ด ์ง€์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.


Scan Multibranch Pipeline Triggers


์ด๋ฒˆ์—” ํ•ด๋‹น Job์„ ํ†ตํ•ด CI/CD๊ฐ€ ๊ฑธ๋ฆด ์ˆ˜ ์žˆ๋Š” Trigger ์„ค์ •์„ ํ•ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

๋‘ ํ•ญ๋ชฉ์„ ๋ชจ๋‘ ํ™œ์„ฑํ™” ์‹œ์ผœ ์ค„๊ฒŒ์š”.

์ตœ์ดˆ pericdically if not otherwise run ์„ค์ •์ด์—์š”.

์ด ์„ค์ •์€ ์ผ๋ถ€ ํด๋” ์œ ํ˜•์€ ์™ธ๋ถ€ ์ด๋ฒคํŠธ๋ฅผ ์ˆ˜์‹ ํ•˜๋Š” ์ฆ‰์‹œ ์ž๋™์œผ๋กœ ๋‹ค์‹œ ์ธ๋ฑ์‹ฑ ๋˜๊ฒŒ ๋˜์š”.
์˜ˆ๋ฅผ ๋“ค์–ด, ๋‹ค์ค‘ ๋ถ„๊ธฐ ํ”„๋กœ์ ํŠธ๋Š” SCM ๋ณ€๊ฒฝ ์•Œ๋ฆผ์„ ์ˆ˜์‹ ํ•  ๋•Œ SCM ์ €์žฅ์†Œ์—์„œ ์ƒˆ ๋ถ„๊ธฐ ๋˜๋Š” ์ œ๊ฑฐ๋˜๊ฑฐ๋‚˜ ์ˆ˜์ •๋œ ๋ถ„๊ธฐ๋ฅผ ๋‹ค์‹œ ํ™•์ธํ•˜๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค. (ํ‘ธ์‹œ ์•Œ๋ฆผ์€ ๊ฐ ๋ถ„๊ธฐ ์†Œ์Šค์— ์‚ฌ์šฉ๋˜๋Š” SCM ํ”Œ๋Ÿฌ๊ทธ์ธ์— ๋”ฐ๋ผ ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.) ๊ทธ๋Ÿฌ๋‚˜ ์ด๋Ÿฌํ•œ ์•Œ๋ฆผ์€ ๋•Œ๋•Œ๋กœ ์‹ ๋ขฐํ•  ์ˆ˜ ์—†๊ฑฐ๋‚˜ Jenkins๊ฐ€ ์•Œ๋ฆผ์„ ๋ฐ›๊ธฐ ์œ„ํ•ด ์‹คํ–‰ํ•˜์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด Jenkins๊ฐ€ ๋ฐฉํ™”๋ฒฝ ๋’ค์— ์žˆ๊ณ  ์™ธ๋ถ€ ์‹œ์Šคํ…œ๋งŒ ํด๋งํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ฆ‰๊ฐ์ ์ธ ์•Œ๋ฆผ์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ํŠธ๋ฆฌ๊ฑฐ๋Š” ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ฃผ๊ธฐ์ ์ธ ํด๋ฐฑ์„ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ง€์ •๋œ ๊ฐ„๊ฒฉ ๋™์•ˆ ์ธ๋ฑ์‹ฑ์ด ์ˆ˜ํ–‰๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์ธ๋ฑ์‹ฑ์ด ์˜ˆ์•ฝ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋‹ค์ค‘ ๋ถ„๊ธฐ ํ”„๋กœ์ ํŠธ์˜ ๊ฒฝ์šฐ ํ‘ธ์‹œ ์•Œ๋ฆผ์— ๋Œ€ํ•ด ์†Œ์Šค ์ œ์–ด ์‹œ์Šคํ…œ์ด ๊ตฌ์„ฑ๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ ์งง์€ ๊ฐ„๊ฒฉ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค(๋Œ€๋ถ€๋ถ„์˜ ์‚ฌ์šฉ์ž๊ฐ€ 15๋ถ„์—์„œ 1์‹œ๊ฐ„ ์‚ฌ์ด๋ฅผ ์„ ํƒํ•จ). ํ‘ธ์‹œ ์•Œ๋ฆผ์„ ์œ„ํ•ด ์†Œ์Šค ์ œ์–ด ์‹œ์Šคํ…œ์ด ๊ตฌ์„ฑ๋œ ๊ฒฝ์šฐ ํ‘ธ์‹œ ์•Œ๋ฆผ์ด ์†์‹ค๋œ ๊ฒฝ์šฐ ์ตœ๋Œ€ ํ—ˆ์šฉ ์ง€์—ฐ ์‹œ๊ฐ„์— ํ•ด๋‹นํ•˜๋Š” ๊ฐ„๊ฒฉ์„ ํ•˜๋ฃจ์˜ ๋งˆ์ง€๋ง‰ ์ปค๋ฐ‹์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. (์ดํ›„ ์ปค๋ฐ‹์€ ์–ด์จŒ๋“  ์ธ๋ฑ์‹ฑ์„ ํŠธ๋ฆฌ๊ฑฐํ•ด์•ผ ํ•˜๊ณ  ์ปค๋ฐ‹์ด ํ”ฝ์—…๋˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์ดˆ๋ž˜ํ•˜๋ฏ€๋กœ ๋Œ€๋ถ€๋ถ„์˜ ์‚ฌ๋žŒ๋“ค์€ 4์‹œ๊ฐ„์—์„œ 1์ผ ์‚ฌ์ด๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.)

Scan Multibranch Pipeline Triggers -> pericdically if not otherwise run


์ด ๊ณณ์—์„œ๋Š” ๋งˆ์ง€๋ง‰ ์ธ๋ฑ์‹ฑ ์ดํ›„ ์ธ๋ฑ์‹ฑ์ด ํŠธ๋ฆฌ๊ฑฐ๋˜๊ธฐ ์ „์— ๊ฒฝ๊ณผํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ์‹œ๊ฐ„์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์–ด์š”.
์˜ˆ: ๊ฐ„๊ฒฉ('5m') // ๋˜๋Š” '2h', '7d', '5000ms', '60s'

์ฃผ๋‹ˆ๋Š” ์ด ์„ค์ •์„ 1 day๋กœ ํ•ด ์ค„๊ฒŒ์š”.


Scan Multibranch Pipeline Triggers -> Scan by Webhook


์ด ๊ณณ์€ ๋ฉ€ํ‹ฐ๋ธŒ๋Ÿฐ์น˜ ๊ฒ€์ƒ‰ ์›น ํ›… ํŠธ๋ฆฌ๊ฑฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 
์ด ๋ฉ€ํ‹ฐ๋ธŒ๋Ÿฐ์น˜ ์ž‘์—…์˜ ๊ฒ€์ƒ‰์„ ํŠธ๋ฆฌ๊ฑฐํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ์ด์—์š”.

Trigger token ๋ถ€์— ๋“ค์–ด๊ฐˆ ๋‚ด์šฉ์€ Gitea์—์„œ Webhook ์„ค์ • ์‹œ Request header์— ๋‹ด์„ Webhook Token์„ ์ง€์ •ํ•ด ์ฃผ๋Š” ๋ถ€๋ถ„์ด์—์š”. ์ฆ‰, Webhook Token๊ณผ ์ผ์น˜์‹œํ‚ฌ Token์„ ์„ค์ •ํ•˜๋Š” ๋ถ€๋ถ„์ด์—์š”.
HTTP Request๋กœ JENKINS_URL/multibranch-webhook-trigger/invoke?token=[ํŠธ๋ฆฌ๊ฑฐ ํ† ํฐ]
์œ„์˜ URI๋ฅผ ์ด์šฉํ•ด์„œ Token์ด ์ผ์น˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์ค‘ ๋ถ„๊ธฐ ๊ฒ€์ƒ‰์ด bi trigger ๋œ๋‹ต๋‹ˆ๋‹ค.

์ด ๊ณณ์€ ์œ„์—์„œ Gitea Access Token ์ €์žฅ ์‹œ ์ด์šฉํ–ˆ๋˜ ID ๊ฐ’์„ ์ง€์ •ํ•ด ์ฃผ๋ฉด ๋œ๋‹ต๋‹ˆ๋‹ค.


์ด๋ ‡๊ฒŒ ์„ค์ •์ด ๋ชจ๋‘ ๋งˆ์ณค์œผ๋ฉด ๋งจ ๋ฐ‘์— Save ํ˜น์€ ์ €์žฅ์„ ๋ˆŒ๋Ÿฌ ํ•ด๋‹น ์„ค์ •์ฐฝ์„ ๋‚˜๊ฐ€๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.


Scan Multibranch Pipeline Log


Log๋ฅผ ํ™•์ธํ•ด ๋ณด๋ฉด ์œ„์™€ ๊ฐ™์ด Jenkinsfile์„ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๊ณ  ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.
์™œ๋ƒํ•˜๋ฉด? ์•ˆ ๋งŒ๋“ค์–ด์คฌ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”!

 

728x90

 

        ๐Ÿ“ฆ Jenkins File ๊ตฌ์„ฑ

์ด๋ฒˆ์—๋Š” Jenkins File์„ ์†Œ์Šค ์ฝ”๋“œ Project์— ๋งŒ๋“ค์–ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.
Jenkins ์ž์ฒด ๋‚ด์— ํ•ด๋‹น ์„ค์ •์„ ํ•ด ์ค„ ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ์ฃผ๋‹ˆ๋Š” Source Code ์ƒ์— ๋„ฃ๋Š” ๋ฐฉ์‹์„ ์„ ํƒํ•˜๋ ค๊ณ  ํ•ด์š”.


์ตœ์ดˆ Project Root Directory ๋ฐ‘์— ์œ„์™€ ๊ฐ™์ด deploy Directory๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.


๊ทธ๋ฆฌ๊ณ  ํ•˜์œ„ Directory์— jenkins Directory๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.



๊ทธ๋ฆฌ๊ณ  ๊ทธ ๋ฐ‘์— ์œ„์™€ ๊ฐ™์ด Jenkins File์„ ๋งŒ๋“ค์–ด ์ค„๊ฒŒ์š”.

 

jenkinsfile

 

pipeline {
    agent any
        stages {
            stage('stage 1') {
                steps {
                    echo "Hello, Juny!! ๐Ÿ˜€"
                }
            }
        }
}


Trigger Test๋ฅผ ์œ„ํ•ด ์œ„์™€ ๊ฐ™์ด ์ž„์‹œ๋กœ ์ž‘์„ฑ์„ ํ•ด ๋ณด์•˜์–ด์š”.

๊ทธ๋Ÿฐ๋ฐ, InteliJ์—์„œ Groovy ํ˜•์‹์˜ Jenkins File์ด ์ธ์‹ ๋˜์ง€ ์•Š์•„ ์ค‘๊ด„ํ˜ธ(Braces) ๋๋‚˜๋Š” ๋ถ€๋ถ„๋„ ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง€๊ณ ,
๋ญ”๊ฐ€ ์ธ์‹ ๋˜์ง€ ์•Š์€ ๋Š๋‚Œ์ด์—์š”.

์ด์— ๋Œ€ํ•œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€ ์ด ๊ณณ์— ์ •์„ฑ์Šค๋Ÿฝ๊ฒŒ ์ค€๋น„ํ•ด ๋‘์—ˆ์–ด์š”.

 

[InteliJ] jenkinsfile Groovy ๋ฌธ๋ฒ• ํ™œ์„ฑํ™”

์ธํ…”๋ฆฌ์ œ์ด IDEA:๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•๋ถ€ํ„ฐ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ๊นŒ์ง€ ๋งˆ์Šคํ„ฐํ•˜๊ธฐ COUPANG www.coupang.com "์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค." ๐Ÿš€ InteliJ ์„ค์ • ๐Ÿ”ฝ Gro

junyharang.tistory.com

 

์—ฌ๊ธฐ๊นŒ์ง€ ๋˜์—ˆ์œผ๋ฉด Jenkins์— Jenkinsfile์„ ์ธ์‹ ์‹œ์ผœ ์ฃผ๊ธฐ ์œ„ํ•ด Gitea๋กœ Push๋ฅผ ํ•ด ์ฃผ๋„๋ก ํ•ด ๋ณผ๊ฒŒ์š”.



Gitea์— ์ •์ƒ์ ์œผ๋กœ jenkinsfile์ด ์˜ฌ๋ผ๊ฐ„ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.



Scan Multibranch Pipelien Log


Log๋ฅผ ๋‹ค์‹œ ๋ณด๋ฉด ์ด๋ฒˆ์—๋Š” Jenkins file์„ ์ฐพ์•˜๋‹ค๊ณ  ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.




 

        ๐Ÿ“ฆ Gitea Webhook ์„ค์ •

์ด๋ฒˆ์—๋Š” Gitea์—์„œ Webhook ์„ค์ •์„ ํ•ด๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

Gitea ๋Œ€์ƒ Repository -> ์„ค์ • -> ์›นํ›…


์ตœ์ดˆ Gitea์— ๋Œ€์ƒ Repository์— ์œ„์™€ ๊ฐ™์ด ์„ค์ •์—์„œ ์›นํ›…์œผ๋กœ ๋“ค์–ด๊ฐ€ ์ค„๊ฒŒ์š”.

๊ทธ๋Ÿฐ ๋’ค webhook ์ถ”๊ฐ€๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



์ด ๊ณณ์—์„œ Gitea๋ฅผ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.



์ตœ์ดˆ ๋Œ€์ƒ URL์—๋Š” ์œ„์—์„œ Jenkins๋ฅผ ํ†ตํ•ด Job์„ ์„ค์ •ํ•  ๋•Œ, 



์œ„์—์„œ ์ž…๋ ฅํ•œ ๊ฐ’์„ {Jenkins Scan by webhook Trigger token Value} ์ด ๋ถ€๋ถ„์„ ์ง€์šฐ๊ณ  ๋„ฃ์–ด์ฃผ๋ฉด ๋˜์š”.

์ฐธ๊ณ ๋กœ URL ๋ถ€๋ถ„์— Jenkins IP ๋ถ€๋ถ„์—๋Š” 80 Port๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด Jenkins IP ๋’ค์— :Port Number๋ฅผ
๊ฐ™์ด ์ž…๋ ฅํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.


์˜ˆ: http://192.168.0.100:8080


๋‚˜๋จธ์ง€๋Š” ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ๋‘๊ณ , ์ฃผ๋‹ˆ๋Š” Branch filter๋ฅผ ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•ด ์ฃผ์—ˆ๋Š”๋ฐ,
dev์™€ master Branch์— ๋Œ€ํ•œ Push Event๋งŒ Webhook์ด ๋™์ž‘ํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•จ์ด์—์š”.

์œ„์™€ ๊ฐ™์ด ์„ค์ •์ด ์™„๋ฃŒ๋˜๋ฉด Webhook ์ถ”๊ฐ€๋ฅผ ๋ˆŒ๋Ÿฌ ์ค๋‹ˆ๋‹ค.



๊ทธ๋Ÿฐ ๋’ค ๋ฐ‘ ๋ถ€๋ถ„์— ์ „๋‹ฌ ์‹œํ—˜์„ ๋ˆŒ๋Ÿฌ ์œ„์™€ ๊ฐ™์ด Response Code๊ฐ€ 200์ด ์˜ค๋Š”์ง€ ํ™•์ธํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.

๋งŒ์•ฝ 200์ด ์˜ค์ง€ ์•Š๋Š”๋‹ค๋ฉด Gitea์™€ Jenkins ํ†ต์‹ ์ด ๋˜์ง€ ์•Š๋Š” ๊ฒƒ์ผ๊ฑฐ์—์š”.

vim /etc/gitea/app.ini


๊ทธ๋Ÿด ๋• Gitea๊ฐ€ ์„ค์น˜ ๋˜์–ด ์žˆ๋Š” Server์—์„œ ์œ„์™€ ๊ฐ™์ด app.ini File์„ ์ˆ˜์ •ํ•ด ์ค„ ํ•„์š”๊ฐ€ ์žˆ์–ด์š”.

app.ini 87 ~ 89


์œ„์™€ ๊ฐ™์ด ALLOWED_HOST_LIST ์ฆ‰, ํ—ˆ์šฉํ•ด์ค„ Host ๋ชฉ๋ก์„ ํ†ตํ•ด Jenkins์˜ ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ฃผ๊ฑฐ๋‚˜,
์ฃผ๋‹ˆ์ฒ˜๋Ÿผ *์„ ๋„ฃ์–ด ๋ชจ๋‘ ํ†ต์‹ ์ด ๋˜๋„๋ก ํ•ด ์ฃผ์–ด์•ผ ํ•˜๊ณ , 89๋ฒˆ์งธ ์ค„์— DISABLE_WEBHOOKS๋ฅผ false๋กœ ํ•ด์ฃผ์–ด Webhook์ด ๋ง‰ํžˆ์ง€ ์•Š๋„๋ก ์„ค์ •ํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.



jenkinsfile


์ •์ƒ์ ์œผ๋กœ ๋˜๋Š”์ง€ ํ™•์ธ์„ ์œ„ํ•ด jenkins File์„ ์ˆ˜์ •ํ•˜๊ณ , ๋‹ค์‹œ Gitea์˜ Master Branch๋กœ Push ํ•ด ๋ณผ๊ฒŒ์š”.



master๋กœ Push๋ฅผ ํ•˜์ž ๋ฐ”๋กœ Jenkins Trigger๊ฐ€ ๊ฑธ๋ ธ๊ณ , ์œ„์™€ ๊ฐ™์ด ์„ฑ๊ณตํ•œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


์œ„์™€ ๊ฐ™์ด Jenkins File์— ์„ค์ •ํ•œ ๋‚ด์šฉ์ด ์ •์ƒ์ ์œผ๋กœ ์ฒ˜๋ฆฌ๋œ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

 

 

 

 

    ๐Ÿ”ฝ  Jenkins File

        ๐Ÿ“ฆ Jenkins์ด๋ž€?

์ฃผ๋‹ˆ๋Š” ์œ„์—์„œ Jenkins์™€ Gitea๋ฅผ ์—ฐ๊ฒฐํ•˜๊ณ , Trigger๊ฐ€ ์ œ๋Œ€๋กœ ๊ฑธ๋ฆฌ๋Š”์ง€ ํ™•์ธ๊นŒ์ง€ ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ด์ œ ๋ณธ๊ฒฉ์ ์ธ ์ž‘์—…์— ์•ž ์จ Jenkins File์ด ๋ฌด์—‡์ธ์ง€ ์•Œ์•„๋ณด๊ณ  ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.

๊ทธ ์ „์— Jenkins File์„ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ, ์„ ์–ธํ˜•(Declarative)๊ณผ ์Šคํฌ๋ฆฝํŠธํ˜•(Scripted)๊ฐ€ ์กด์žฌํ•ด์š”.

1. Pipe Line Script ์ž‘์„ฑ ๋ฐฉ์‹ ๋‘๊ฐ€์ง€
  1)Declarative
  2)Scripted
(Groovy + DSL)

2. ์ฐจ์ด์ 
  - ์‹œ์ž‘ ์‹œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์œ ๋ฌด
    - ํŠน์ • Stage ์‹คํ–‰ ๊ฐ€๋Šฅ ์—ฌ๋ถ€
    - ์ œ์–ด๋ฌธ
    - Option
    - ๊ฐ๊ฐ์˜ Pipe Line์„ ์ง„ํ–‰ํ•˜๋‹ค๊ฐ€ ์–ด๋–ค ์ž‘์—…์ด ์‹คํŒจํ–ˆ์„ ๋•Œ,Declarative๋ฐฉ์‹์€ ๊ทธ ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ณ ,         
Scripted๋ฐฉ์‹์€ ๊ทธ ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰.

 

Declarative ๋ฐฉ์‹

pipeline {
	agent any
    stage {
    	steps('build') {
        	//
        }
        
        steps('test') {
        	//
        }
        
        steps('deploy')	{
        	//
        }
}

 

1. agent : Jenkins Server๋ฅผ ๊ธฐ๋™ํ•  ๋•Œ, Master Server์™€ Slave Server๋กœ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์–ด๋–ค Server์—
                      Jenkins๋ฅผ ์‹คํ–‰ํ• ์ง€๋ฅผ ์ง€์ •. any๋ฅผ ์ง€์ •ํ–ˆ์„ ๋•Œ๋Š” ๊ตฌ์„ฑ๋œ Server ์ค‘ ์–ด๋–ค Server๋„ ๊ด€๊ณ„ ์—†์œผ๋‹ˆ
                      ์‹คํ–‰ํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ.

2. Stages : ๊ตฌ์„ฑํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฐ๊ฐ์˜ ๋‹จ๊ณ„์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์‚ฝ์ž….

  1)build: build Stage ์„ ์–ธ ๋ฐ ํ•˜์œ„์— build Stage์— ํ•„์š”ํ•œ ์ž‘์—… ๋ช…๋ น์–ด ๋“ฑ ์ž…๋ ฅ.
  2)test: test Stage ์„ ์–ธ ๋ฐ ํ•˜์œ„ test Stage์— ํ•„์š”ํ•œ ์ž‘์—… ๋ช…๋ น์–ด ๋“ฑ ์ž…๋ ฅ.
  3)deploy: deploy Stage ์„ ์–ธ ๋ฐ ํ•˜์œ„ deploy Stage์— ํ•„์š”ํ•œ ์ž‘์—… ๋ช…๋ น์–ด ๋“ฑ ์ž…๋ ฅ.

Jenkinsfile









๐Ÿง ์ฐธ๊ณ  ์ž๋ฃŒ

 

[DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘  - Pipeline

์ด ๋‚ด์šฉ์€ ์ธํ”„๋Ÿฐ - Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ ์ž…๋‹ˆ๋‹ค. ํ•ด๋‹น ๋‚ด์šฉ์˜ Code ๋‚ด์šฉ์€ ์ด ๊ณณ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ—‚ ๋ชฉ์ฐจ โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ

junyharang.tistory.com

 

 

์  ํ‚จ์Šค ๋งˆ์Šคํ„ฐ

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

๋‹ค์Œ ๊ธ€: [CI/CD] Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•