๐Ÿ”” ์  ํ‚จ์Šค ํŒŒ์ดํ”„๋ผ์ธ์„ ํ™œ์šฉํ•œ ๋ฐฐํฌ ์ž๋™ํ™”

  • ํŒŒ์ดํ”„๋ผ์ธ์„ ํ™œ์šฉํ•˜์—ฌ ๋ฐฐํฌ ์ž๋™ํ™”

ย 

๐Ÿ“š 1. Jenkins ์–ด๋–ค ๊ตฌ์กฐ๋กœ ๋™์ž‘ํ• ๊นŒ?

โœ”๏ธ ํ˜„์žฌ ์ƒํ™ฉ
ํ”„๋กœ์ ํŠธ์— ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด์„œ base branch์— merge ๋˜์—ˆ๋‹ค. ์ด์ œ ์‹ค์ œ ์„œ๋ฒ„์— ๋ฐฐํฌ๋ฅผ ํ•ด์•ผํ•˜๊ฒ ๋‹ค.

ย 

โœ”๏ธ ํŒ€ํ”„๋กœ์ ํŠธ์—์„œ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” work flow - ํ˜„์žฌ ๋งค๋ฒˆ ์‹คํ–‰๋˜์–ด์•ผ ํ•œ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 12 54 46 (1) ๊ฐ ๊ฐœ๋ฐœ์ž๊ฐ€ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ ํ›„ PR (2) EC2 ์„œ๋ฒ„๋กœ ์ ‘์† (3) github์— merge๋œ ์ฝ”๋“œ๋ฅผ git pull (4) gradle์„ ์ด์šฉํ•ด bootJar (5) jar ํŒŒ์ผ์„ java -jar ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด 80port์— ์‹คํ–‰ํ•œ๋‹ค.

=> 5๊ฐ€์ง€๋ฅผ ๋งค๋ฒˆ ์‹คํ–‰ํ•ด์•ผ ํ•œ๋‹ค. ๊ท€์ฐฎ์ง€ ์•Š์€๊ฐ€? Jenkins๋ฅผ ์ด์šฉํ•˜๋ฉด ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

ย 

๐Ÿ’ก ์ฐธ๊ณ 

  • ์„œ๋ฒ„ ๋ฐฐํฌ๋Š” ๋งค๋ฒˆ ๊ธฐ๋Šฅ์ด ์ถ”๊ฐ€๋  ๋•Œ๋งˆ๋‹ค ์‹œํ–‰๋˜์–ด์•ผ ํ•œ๋‹ค.
  • ํ˜„์žฌ flow๋Š” ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ๋งˆ๋‹ค ๋ฐ”๋€Œ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์—, ์ž๋™ํ™” ํ•  ์ˆ˜ ์žˆ๋Š” ๋Œ€์ƒ์ด๋‹ค.

ย 

โœ”๏ธ Continuous Distribution - ์ง€์†์  ๋ฐฐํฌ

flow๋ฅผ ์ž๋™ํ™”ํ•˜์—ฌ ์ตœ์‹  ์ƒํƒœ์˜ ์ฝ”๋“œ๊ฐ€ ์ž๋™์œผ๋กœ ๋ฐฐํฌ๋˜๋Š” ๊ฒƒ

ย 

โœ”๏ธ Jenkins๊ฐ€ ํ•ด์ฃผ๋Š” ๊ฒƒ์€?
Jenkins๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ํ•ด์ฃผ์ง€๋Š” ์•Š๋Š”๋‹ค.

Jenkins๊ฐ€ ํ•ด์ฃผ๋Š” ๋ถ€๋ถ„์€?
(1) github์œผ๋กœ๋ถ€ํ„ฐ merge ๋˜์—ˆ๋‹ค๋Š” ์—ฐ๋ฝ์„ ๋ฐ›์•„์„œ
(2) ์ฝ”๋“œ๋ฅผ git cloneํ•˜๊ณ 
(3) gradle๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ build ํ•˜์—ฌ
(4) buildํ•œ ๋ชฉ์ ํŒŒ์ผ์„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋˜์–ด์•ผ ํ•  ์„œ๋ฒ„๋กœ ์ „๋‹ฌํ•˜๊ณ , ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ๋™ํ•˜๊ธฐ ์œ„ํ•œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

ย 

โœ”๏ธ Jenkins์˜ ์„ค์ •์ด ๋ฐฐํฌ๋ฅผ ํ• ๋•Œ ์–ด๋–ค ๋ถ€๋ถ„์„ ์ž๋™ํ™” ํ•ด์ฃผ๋Š” ๊ฑธ๊นŒ?

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 8 31 46

ย 

๐Ÿ’ก ์ฐธ๊ณ 
์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„์—์„œ Jenkins๋ฅผ ๊ตฌ๋™ํ•  ๊ฒฝ์šฐ, ๋นŒ๋“œ๊ฐ€ ์ง„ํ–‰๋  ๋•Œ๋งˆ๋‹ค CPU ์ž์›์ด ๋ชจ์ž๋ผ์„œ ์„œ๋ฒ„๊ฐ€ ๋‹ค์šด๋˜๋Š” ์ผ์ด ์žˆ๋‹ค.
์ด๋กœ ์ธํ•ด ๋ณ„๋„ EC2๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.
๋งŒ์•ฝ, ์„œ๋ฒ„ ์ž์›์ด ๋ชจ์ž๋ผ๊ฑฐ๋‚˜ ์—ฌ๋Ÿฌ ๊ฐœ์˜ WAS๋ฅผ ๋„์šธ ์ผ์ด ์ƒ๊ธด๋‹ค๋ฉด, ๋ณ„๋„ ํ™˜๊ฒฝ์œผ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.

ย 

โœ”๏ธ Ubuntu ์ดˆ๊ธฐ์„ค์ •(20.04)

sudo apt-get update
sudo apt-get install apache2
sudo apt-get install openjdk-11-jdk

ย 

Jenkins ์„ค์น˜ ์ฐธ๊ณ 

  • sudo cat ~/initialAdminPassword : ์ฒซ ์„ค์น˜์‹œ ํ•„์š”ํ•œ password

ย 

๐Ÿ’ก ์ฐธ๊ณ 
sudo apt-get install openjdk-11-jdk : java 11 jdk ์„ค์น˜

ย 

๐Ÿ“š 2. credentials ์„ธํŒ…

์ปดํ“จํ„ฐ๊ฐ€ ๋‚˜ ๋Œ€์‹ ์— git clone์„ ํ•˜๊ฒŒ ํ•˜๋ ค๋ฉด ํ•ด๋‹น ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ๋Œ€ํ•œ ๊ถŒํ•œ์ด ํ•„์š”ํ•˜๋‹ค!

ย 

๐Ÿ’ก ์ฐธ๊ณ 

  • ๊ณต๊ฐœ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์žˆ๋Š” ์†Œ์Šค์ฝ”๋“œ๋ฅผ clone ํ•˜๋Š” ๋ชฉ์ ์ด๋ผ๋ฉด ๊ถŒํ•œ์ด ํ•„์š”์—†๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ๋กœ credentials๋ฅผ ์„ค์ •ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค.
  • PipeLine ์ƒ์—์„œ push ๋˜๋Š” ์„œ๋ธŒ๋ชจ๋“ˆ ๋“ฑ ๊ถŒํ•œ์ด ํ•„์š”ํ•œ ์ผ์ด ์žˆ๋‹ค๋ฉด credentials์ด ํ•„์š”ํ•˜๋‹ค.

ย 

๐Ÿ“– A. access token ๋ฐœ๊ธ‰ ๋ฐ test

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 11 00 02
  • ์‹œ์Šคํ…œ ์„ค์ •

ย 

โœ”๏ธ github repository ์—ฐ๊ฒฐ
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 11 02 04

  • github ํƒญ์œผ๋กœ ์ด๋™, add ๋ˆ„๋ฅธ๋‹ค.
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 11 10 47 - Secret text ์„ ํƒ, Secret(github token), ID๋Š” ์•„๋ฌด๊ฑฐ๋‚˜

ย 
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 11 10 53

  • test Connection์ด ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ ์„ฑ๊ณต

ย 

โœ”๏ธ credentials์ด ํ•„์š”ํ•˜๋‹ค (๋ฏธ๋ฆฌ ์ƒ์„ฑํ•˜์ž)

  • ์‹œ์Šคํ…œ ์„ค์ •์˜ github๊ณผ ์—ฐ๊ด€๋œ ๊ฒƒ์€ credentials์— Secret text๋กœ ๋“ฑ๋กํ•œ credentials๋งŒ ์ธ์‹ํ•œ๋‹ค.
  • ์ง€๊ธˆ์€ Username with password ๋กœ ์ƒ์„ฑํ•œ credentials์ด ํ•„์š”ํ•˜๋‹ค.

ย 

โœ”๏ธ ๋“ฑ๋ก ํ˜น์€ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.

credentials๋Š” ์ถ”ํ›„ manage credentials์—์„œ ๋“ฑ๋ก ํ˜น์€ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 11 17 45 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 11 20 38

ย 

ย 

๐Ÿ“š 2. ํŒŒ์ดํ”„๋ผ์ธ ์ƒ์„ฑํ•˜๊ธฐ

๐Ÿ’ก ์ฐธ๊ณ 

  • ๊ฐ„๋‹จํ•œ Job์„ ์œ„ํ•ด์„  freestyle๋„ ์ข‹์€ ์„ ํƒ (๋น„๊ต์  ์„ธํŒ…์ด ๋‹จ์ˆœ)
  • ๋ณต์žกํ•œ ์ข…๋ฅ˜์˜ Job๊ฐ„์˜ ์—ฐ๊ณ„๋‚˜ ์ƒ์„ธํ•œ ์„ธํŒ…, UI (๊ฐ job๋ณ„๋กœ ์–ด๋–ป๊ฒŒ ์ง„ํ–‰๋˜๊ณ  ์žˆ๋Š”์ง€ ๋ณด์—ฌ์ค€๋‹ค.)๋ฅผ ์›ํ•œ๋‹ค๋ฉด ํŒŒ์ดํ”„๋ผ์ธ์„ ์„ ํƒ
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 11 25 04

ย 

โœ”๏ธ pipeline script

pipeline script์€ Groobee ๋˜๋Š” Jenkins์—์„œ ์ •์˜ํ•œ pipeline syntax๋ฅผ ํ†ตํ•ด item์—์„œ ์ˆ˜ํ–‰ํ•  Job์„ ์„ ์–ธํ•˜๊ณ , ์ˆœ์„œ๋ฅผ ์กฐ์ •ํ•˜๊ณ , ํ™˜๊ฒฝ์„ ์„ค์ •ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

PipeLine ๊ณต์‹๋ฌธ์„œ

ย 

โœ”๏ธ pipeline syntax

ํ”Œ๋Ÿฌ๊ทธ์ธ ๋ณ„๋กœ syntax๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 21 05

(1) pipe line์€ ์ด ํŒŒ์ดํ”„๋ผ์ธ ์ž์ฒด๋ฅผ ์˜๋ฏธํ•œ๋‹ค.
(2) agent๋Š” ์ด ํŒŒ์ดํ”„๋ผ์ธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•  executor๋ฅผ ์ง€์ •ํ•œ๋‹ค. any๋กœ ๋‘˜ ์‹œ ์–ด๋–ค executor๋„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์˜๋ฏธ๊ฐ€ ๋œ๋‹ค.
(3) stages๋Š” ์‹คํ–‰ํ•  Job๋“ค์˜ ์ง‘ํ•ฉ์ด๋‹ค.
(4) stage๋Š” ๊ฐ๊ฐ์˜ Job์„ ์˜๋ฏธํ•œ๋‹ค. Job ๋‚ด๋ถ€์˜ ๋‹จ๊ณ„๋ฅผ ์˜๋ฏธํ•˜๋Š” steps๋ฅผ ํฌํ•จํ•ด์•ผํ•œ๋‹ค.
(5) steps์—์„  ์‹ค์ œ๋กœ ์‹คํ–‰ํ•  ์‰˜์ด๋‚˜ syntax๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

ย 

ย 

๐Ÿ“š 3. Git Clone ํ•˜๊ธฐ

git clone ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” syntax๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค. (pipeline syntax๋ฅผ ํด๋ฆญ)

pipeline syntax -> snippet generate click

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 28 56 - git check

ย 

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 29 12 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 33 17
  • repository url์„ ์ ์–ด์ฃผ๊ณ , branch๋ฅผ ์„ ํƒํ•˜๊ณ , credentials๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.
  • ์•„๊นŒ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ง€๊ธˆ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
  • ๊ณต์šฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ cloneํ•˜๋Š” ์ž…์žฅ์ด๋ผ๋ฉด ๋น„์›Œ๋†“์•„๋„ ๋œ๋‹ค.

ย 

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 34 19
  • generate๋ฅผ ๋ˆ„๋ฅด๋ฉด ์Šค๋‹ˆํŽซ์ด ์ƒ์„ฑ๋œ๋‹ค. ํ•ด๋‹น ๋‚ด์šฉ์„ ๋ณต์‚ฌํ•˜์ž!

ย 

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 36 54 - `stage` ์ด๋ฆ„์„ ์›ํ•˜๋Š” ์ด๋ฆ„์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ , `steps`์—๋Š” ์œ„์—์„œ ์ƒ์„ฑํ•œ `snippet`์„ ๋ถ™์—ฌ์ฃผ๋ฉด ๋œ๋‹ค. - **์ฝ์–ด๋ณด๋ฉด, git ํŠน์ • ๋ธŒ๋žœ์น˜์—์„œ ํŠน์ • `credentials`๋กœ url์˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ ์†Œ์Šค๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” `snippet`์ด๋‹ค.**

=> ์ด์ œ ์ €์žฅ์„ ๋ˆ„๋ฅด๋ฉด, github์„ clone ํ•˜๋Š” job์„ ๊ฐ€์ง„ ํŒŒ์ดํ”„๋ผ์ธ์„ ์ƒ์„ฑํ•œ ๊ฒƒ์ด๋‹ค.

ย 

๐Ÿ’ก ์ฐธ๊ณ 

  • ํ•œ ๋ฒˆ์— ์ „์ฒด job์„ ์ž‘์„ฑํ•˜๋ฉด trouble shooting์ด ํž˜๋“ค์–ด์ง€๋ฏ€๋กœ ๊ฐ ๋‹จ๊ณ„๋ณ„๋กœ ํ…Œ์ŠคํŠธ ํ•˜์ž.
  • ๋Œ€์‰ฌ๋ณด๋“œ์—์„œ ์ƒ์„ฑํ•œ ์•„์ดํ…œ์„ ํด๋ฆญํ•˜์—ฌ ๋“ค์–ด๊ฐ‘์‹œ๋‹ค.

ย 

โœ”๏ธ ์ด์ „๊นŒ์ง€ ์ž‘์—…ํ•œ ๋‚ด์šฉ ํ…Œ์ŠคํŠธ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 45 42 - ์ˆ˜๋™์ ์œผ๋กœ build ํ• ์‹œ, job์„ ์œ ๋ฐœํ•œ๋‹ค. - ์‹คํ–‰๋˜์–ด Build History์— ์ž˜ ๋“ค์–ด๊ฐ„ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

ย 

โœ”๏ธ ๋นŒ๋“œ ๊ณผ์ •์—์„œ ์ถœ๋ ฅ๋˜๋Š” ์ฝ˜์†”๋ฌธ์€ console output ํƒญ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 49 59 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-14 แ„‹แ…ฉแ„’แ…ฎ 2 50 06 - `pipeline` job์˜ ์ง„ํ–‰ ๊ฒฝ๊ณผ ๋ฐ `github clone`์„ ์ง„ํ–‰ํ•˜๋ฉฐ ์ž…๋ ฅ๋œ ๋ช…๋ น์–ด์™€ ์ถœ๋ ฅ๋ฌธ๋“ค์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

ย 

ย 

๐Ÿ“š 4. Build

๐Ÿ“ฃ ์‹œ์ž‘ํ•˜๊ธฐ์ „

  • ๋นŒ๋“œ๋Š”(Build) cloneํ•ด ์˜จ ์†Œ์Šค์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” gradle wrapper๋ฅผ ํ™œ์šฉํ•œ๋‹ค!
  • ํ”„๋กœ์ ํŠธ์—์„œ .gradlew ์œ„์น˜๋ฅผ ์ฐพ์•„์•ผ ํ•œ๋‹ค.
  • dir ์Šค๋‹ˆํŽซ : cd
  • sh ''' ${์‰˜ ๋ช…๋ น์–ด} ''' : pipeline syntax์—์„œ ์‰˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๋ถ€๋ถ„
  • ํ˜„์žฌ ๋นŒ๋“œ๋ฅผ ์œ„ํ•ด ์‹คํ–‰ํ•ด์•ผํ•  ํ…Œ์ŠคํŠธ : clean, bootJar

ย 

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 12 09 24
pipeline {
    agent any

    stages {
        stage('github clone') {
            steps {
                git branch: 'main', credentialsId: 'repo-and-hook-access-token-credentials', url: 'https://github.com/ToDoStudy/study_jenkins'
            }
        }
        
        stage('build'){
            steps {
                dir('jenkins') {
                    sh '''
                        echo 'start bootJar'
                        ./gradlew clean bootJar
                    '''
                }
            }
        }
    }
}

ย 

โœ”๏ธ ์Šค๋‹ˆํŽซ(snippet)
์Šค๋‹ˆํŽซ(snippet) :ย ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์†Œ์Šค ์ฝ”๋“œ, ๊ธฐ๊ณ„์–ด, ํ…์ŠคํŠธ์˜ ์ž‘์€ ๋ถ€๋ถ„์„ ์ผ์ปซ๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์šฉ์–ด

  • dir : cd
  • stages : ์‹คํ–‰ํ•  Job๋“ค์˜ ์ง‘ํ•ฉ
  • stage : ๊ฐ๊ฐ์˜ Job์„ ์˜๋ฏธ

ย 

โœ”๏ธ build ๊ฒฐ๊ณผ(์‹คํŒจ)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 12 03 47 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 12 00 24 - ํ˜„์žฌ ์„œ๋ธŒ ๋ชจ๋“ˆ์„ initํ•˜๊ณ  updateํ•˜์ง€ ์•Š๋Š”๋‹ค!

ํ˜„์žฌ ์‹คํŒจํ•œ ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ฒŒ ๋˜์—ˆ๋‹ค. ์ด์œ ๋Š”?
์ฝ”๋“œ๋ฅผ ๋นŒ๋“œํ•  ๋•Œ ์„œ๋ธŒ๋ชจ๋“ˆ์ด ํ•„์š”ํ•œ๋ฐ, ํ•ด๋‹น ๋‚ด์šฉ์„ ๊ณ ๋ คํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. (๋งŒ์•ฝ์—, ์„œ๋ธŒ ๋ชจ๋“ˆ์ด ์—†์—ˆ๋‹ค๋ฉด ์„ฑ๊ณต์ด๋‹ค!)

git plugin snippet์€ ์„œ๋ธŒ ๋ชจ๋“ˆ์˜ init๊ณผ update๊นŒ์ง€ ์ง€์›ํ•ด์ฃผ์ง€ ์•Š๋Š”๋‹ค.

=> ์ด๋ ‡๊ฒŒ ์ƒ์„ฑํ•œ syntax๊ฐ€ ์›ํ•˜๋Š”๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ๋‹ค๋ฅธ step์„ ์ฐพ๊ฑฐ๋‚˜, ๊ณต์‹๋ฌธ์„œ๋ฅผ ํ†ตํ•ด ์›ํ•˜๋Š” ์„ค์ •์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค.

ย 

โœ”๏ธ ์„œ๋ธŒ๋ชจ๋“ˆ๊นŒ์ง€ ๋ฐ›์•„์˜ค๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ step syntax์„ ํ™œ์šฉํ•ด๋ณด์ž

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 12 23 08

์„œ๋ธŒ ๋ชจ๋“ˆ๊นŒ์ง€ ๋ฐ›์•„์˜ค๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค๋ฅธ step syntax์„ ํ™œ์šฉํ•ด๋ณด์ž!
checkout์œผ๋กœ ๊ฒ€์ƒ‰ํ•˜์—ฌ ํ•ด๋‹น simple step์„ ์„ ํƒํ•œ๋‹ค.
private repository๋กœ ๋“ฑ๋กํ•œ ์„œ๋ธŒ๋ชจ๋“ˆ์„ ๋ฐ›์•„์˜ค๊ธฐ ์œ„ํ•œ ์—ฌ์ •์ด๋ฏ€๋กœ! credentials๋ฅผ ์„ธํŒ…ํ•ด์ค€๋‹ค.

ย 

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 12 24 19 - `pipeline syntax`์—์„œ `additional behaviours`์˜ add ๋ฒ„ํŠผ์„ ํด๋ฆญํ•œ ํ›„, `Advanced sub-modules behaviours`๋ฅผ ๋ˆŒ๋Ÿฌ ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•ด์ค€๋‹ค. - `Generate Pipeline Script`์„ ๋ˆŒ๋Ÿฌ์„œ, ๋ถ€๋ชจ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ `credentials`๋ฅผ ๊ทธ๋Œ€๋กœ ํ™œ์šฉํ•œ๋‹ค.

ย 

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 12 27 35 - ์ƒ์„ฑํ•œ `pipeline script`๋ฅผ steps ํ•˜์œ„์— ๋ถ™์—ฌ๋„ฃ์–ด์„œ **๊ธฐ์กด์˜ `git syntax`๋ฅผ ๋Œ€์ฒดํ•ด์ค€๋‹ค.** - ์„œ๋ธŒ ๋ชจ๋“ˆ ๊ด€๋ จ ๋ช…๋ น์–ด๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ๋‹ค.

ย 

โœ”๏ธ ํ˜„์žฌ๊นŒ์ง€์˜ ํŒŒ์ดํ”„๋ผ์ธ

pipeline {
    agent any

    stages {
        stage('github clone') {
            steps {
                checkout scmGit(branches: [[name: '*/main']], extensions: [submodule(parentCredentials: true, reference: '', trackingSubmodules: true)], userRemoteConfigs: [[credentialsId: 'repo-and-hook-access-token-credentials', url: 'https://github.com/ToDoStudy/study_jenkins']])
            }
        }
        
        stage('build'){
            steps {
                dir('jenkins') {
                    sh '''
                        echo 'start bootJar'
                        ./gradlew clean bootJar
                    '''
                }
            }
        }
    }
}

ย 

โœ”๏ธ ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ

์ฒ˜์Œ์—๋Š” 3์‹œ๊ฐ„ ์ •๋„ ๊ธฐ๋‹ค๋ ค๋„ ๋นŒ๋“œ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์—ˆ๋‹ค. (์ด๋Š” ๊ฐ€์ƒ๋ฉ”๋ชจ๋ฆฌ ec2 ๋ฉ”๋ชจ๋ฆฌ ํฌ๊ธฐ๊ฐ€ 1GB ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.) ํ•ด๊ฒฐ์ฑ… : EC2 ๋ฉ”๋ชจ๋ฆฌ ํฌ๊ธฐ 1GB + 2GB ์ถ”๊ฐ€

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 10 10 16 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 10 09 20 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 10 09 30

ย 

ย 

๐Ÿ“š 5. ssh๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ๋ฒ„๋กœ jar ํŒŒ์ผ ์ „๋‹ฌํ•˜๊ธฐ

์ด์ œ ๋ฐฐํฌ์šฉ Jenkins์—์„œ WAS์šฉ EC2๋กœ Build ๊ฒฐ๊ณผ ํŒŒ์ผ์„ ์ „๋‹ฌํ•ด์•ผ ํ•œ๋‹ค.
์ด๋ฅผ ์œ„ํ•ด์„œ๋Š” Publish over ssh ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํ™œ์šฉํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

โœ”๏ธ ํ”Œ๋Ÿฌ๊ทธ์ธ ์ถ”๊ฐ€
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 3 09 15
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 3 09 59

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 3 11 48
  • ssh๋ฅผ ํ†ตํ•ด ํŒŒ์ผ์„ ๋ณด๋‚ด๊ธฐ์ „์—, pemํ‚ค์˜ ์ •๋ณด๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
  • EC2์— ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋Š” pemํ‚ค์˜ ๋‚ด์šฉ์„ ์–ป์–ด์˜จ ํ›„, ๋‚ด์šฉ์„ ๋ณต์‚ฌํ•œ ํ›„, EC2 ์ ‘์†์— ํ•„์š”ํ•œ pemํ‚ค์˜ ๋‚ด์šฉ์„ ์‚ฌ์ง„ key์— ๋ถ™์—ฌ๋„ฃ์–ด ์ค€๋‹ค.
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 4 20 56 `Name` : syntax์—์„œ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ๋Š” ์ด๋ฆ„ `HostName` : ๋นŒ๋“œ๋œ ํŒŒ์ผ์„ ์ „์†กํ•  ์„œ๋ฒ„์˜ private ip (๊ฐ™์€ vpc์— ์†ํ•ด์žˆ์–ด private ip๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.) `username` : ubuntu(default) `Remote Directory` : ํŒŒ์ผ์ด ๋„์ฐฉํ•  ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์ ์–ด์ค€๋‹ค. (ec2 ๊ฐ€์ƒ์„œ๋ฒ„์—์„œ ์ƒ์„ฑํ•œ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ํ•ด์ค˜์•ผํ•จ ์•„๋‹ˆ๋ฉด, `jenkins.plugins.publish_over.bappublisherexception` ๋ฐœ์ƒ) แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 4 28 24 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 4 29 46 ํ˜„์žฌ๋Š” `/home/ubuntu`๋กœ ๋ณ€๊ฒฝ แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 4 28 55

ย 

๐Ÿ’ก ์ฐธ๊ณ 
(Ubuntu22๋ฒ„์ „ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ jenkins.plugins.publish_over.bappublisherexception: failed to connect and initialize ssh connection. message: failed to connect session for config ์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๋ฅผ ๋งŒ๋‚  ์ˆ˜๋„ ์žˆ์œผ๋‹ˆ Ubuntu20.04.5 ์‚ฌ์šฉํ•˜๊ธฐ๋ฅผ ๊ถŒ์žฅํ•œ๋‹ค.) -> ๋‚ด๊ฐ€ ๊ฒฝํ—˜ํ•œ ์˜ค๋ฅ˜

ย 

ย 

๐Ÿ“– A. snippet์„ ๋งŒ๋“ค์–ด๋ณด์ž! - sshPublisher simple step

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 40 00 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 40 11
  • ssh Server ์„ค์ •์—์„œ ์„ ์–ธํ•œ name์„ ๋„ฃ์–ด์ค€๋‹ค. (์›๋ž˜ ์ž๋™์œผ๋กœ ๋“ค์–ด๊ฐ„๋‹ค.)
  • Source files : ์†Œ์ŠคํŒŒ์ผ์˜ ์œ„์น˜, gradlew wrapper์—์„œ ๋นŒ๋“œ ๊ฒฐ๊ณผ๋ฌผ์„ build/libs/๋กœ ์œ„์น˜ํ•˜๋ฏ€๋กœ, build/libs/*.jar ๋กœ ์ž‘์„ฑํ•˜์˜€๋‹ค.
  • Remove prefix : ์†Œ์ŠคํŒŒ์ผ์—์„œ ์›๋ณธํŒŒ์ผ์˜ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์–ด๋””๊นŒ์ง€ ํฌํ•จํ•  ๊ฒƒ์ธ์ง€์— ๋Œ€ํ•œ ์„ค์ •
  • remote directory : ๋ฐฐํฌ๋  ๊ฒฝ๋กœ๋ฅผ ์ ๋Š”๋‹ค. ๋ฐฐํฌ ์„œ๋ฒ„์˜ ํ•ด๋‹น ํด๋”๋กœ ๋ชฉ์ ํŒŒ์ผ์ด ๋„์ฐฉํ•˜๊ฒŒ ๋œ๋‹ค. (๋””๋ ‰ํ„ฐ๋ฆฌ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.)
  • Exec command : ์ „์†ก์„ ๋งˆ์น˜๊ณ  ์‹คํ–‰ํ•  shell ๋ฌธ์˜ ๋””๋ ‰ํ„ฐ๋ฆฌ ๋ฐ ํŒŒ์ผ ์œ„์น˜์ด๋‹ค.

ย 

โœ”๏ธ ํ”„๋กœ์ ํŠธ์—์„œ ์ œ๊ณตํ•˜๋Š” ๋ฐฐํฌ ์‰˜

echo "> pid ํ™•์ธ"
CURRENT_PID=$(ps -ef | grep java | grep D208 | grep -v nohup | awk '{print $2}')
echo "$CURRENT_PID"
if [ -z ${CURRENT_PID} ] ;then
	echo "> ํ˜„์žฌ ๊ตฌ๋™์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์—†์œผ๋ฏ€๋กœ ์ข…๋ฃŒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."
else
	echo "> sudo kill -9 $CURRENT_PID"
	sudo kill -9 $CURRENT_PID
	sleep 10
fi
echo "> jujeol ๋ฐฐํฌ"
JAR_PATH=$(ls -t /home/ubuntu/D208-Project/deploy/*.jar | head -1)
sudo nohup java -jar ${JAR_PATH} >> /home/ubuntu/D208-Project/logs/D208.log &
  • CURRENT_PID=$(ps -ef | grep java | grep D208 | grep -v nohup | awk '{print $2}') : CURRENT_PID์— ํ˜„์žฌ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์˜ pid๋ฅผ ๋ฐ›์•„์˜จ๋‹ค.
  • ์‰˜์„ ์ž‘์„ฑํ•˜๊ธฐ ์ „ ์ง์ ‘ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ํ•ด๋‹น ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด์„œ pid๋ฅผ ์ž˜ ์žก์•„์˜ค๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.
    • ps -ef | grep java | grep D208 | grep -v nohup | awk '{print $2}'
  • CURRENT_PID๊ฐ€ ์žˆ๋‹ค๋ฉด ๋จผ์ € ์ข…๋ฃŒํ•œ๋‹ค. (์…ง๋‹ค์šด ์‹œ๊ฐ„์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— sleep์„ ํ•ด์ค€๋‹ค.)
  • ์ข…๋ฃŒ๊ฐ€ ๋๋‚˜๋ฉด deploy ํด๋”์—์„œ ๋งˆ์ง€๋ง‰ jar์„, 80port์— dev ํ”„๋กœํ•„๋กœ ์‹คํ–‰ํ•œ๋‹ค.

ย 

๐Ÿ“ ๋ฆฌ๋ˆ…์Šค 2>&1 ๊ทธ๋ฆฌ๊ณ  /dev/null
์ฐธ๊ณ  : https://inpa.tistory.com/entry/%EB%A6%AC%EB%88%85%EC%8A%A4-devnull-%EB%A6%AC%EB%8B%A4%EC%9D%B4%EB%A0%89%EC%85%98-%EA%B8%B0%ED%98%B8-%EC%A2%85%EB%A5%98
(1) 2>&1
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 53 40แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 53 56
(2) /dev/null

  • /dev/null๋กœ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋‚ธ๋‹ค๋Š” ๊ฒƒ์€, ๋ฐ์ดํ„ฐ๋ฅผ ์ฃ„๋‹คย ๋ง๋”ํžˆ ์—†์• ๋ฒ„๋ ค์„œย ๊น”๋”ํ•˜๊ฒŒ ํ™”๋ฉด์— ํ‘œ์‹œํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค.
    แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 56 44

ย 
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 40 18

  • Generate Pipeline Scriptํด๋ฆญ์„ ํ†ตํ•ด ๋ฐœ๊ธ‰ ๋ฐ›๋Š”๋‹ค.
  • snippet์„ stage๋กœ ๋งŒ๋“ค์–ด๋ณด์ž.
  • sshPublisher ๊ฐ™์€ ๊ฒฝ์šฐ verbose ์˜ต์…˜์ด ์žˆ๋Š”๋ฐ, ํ•ด๋‹น ์˜ต์…˜์„ true๋กœ ์ฃผ๋ฉด ํŠธ๋Ÿฌํ”Œ ์ŠˆํŒ…์‹œ ์œ ์šฉํ•˜๋‹ค. ๋นŒ๋“œ์˜ console output์— ํ•ด๋‹น ๋‚ด์šฉ์ด ์ƒ์„ธํžˆ ์ฐํžŒ๋‹ค. (true ์ค„ ์‹œ, ๋””๋ฒ…)

ย 

ํ˜„์žฌ๊นŒ์ง€์˜ ํŒŒ์ดํ”„๋ผ์ธ

pipeline {
    agent any

    stages {
        stage('git clone') {
            steps {
                checkout scmGit(branches: [[name: '*/main']], extensions: [submodule(parentCredentials: true, reference: '', trackingSubmodules: true)], userRemoteConfigs: [[credentialsId: 'repo-and-hook-access-token-credentials', url: 'https://github.com/ToDoStudy/study_jenkins']])
            }
        }
        
        stage('build'){
            steps {
                dir('jenkins') {
                    sh '''
                        echo 'start bootJar'
                        ./gradlew clean bootJar
                    '''
                }
            }
        }
        
        stage('publish on ssh'){
            steps{
                dir('jenkins'){
                    sshPublisher(publishers: [sshPublisherDesc(configName: 'ECGumD208', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'sh /home/ubuntu/D208-Project/script/init_server.sh', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/D208-Project/deploy', remoteDirectorySDF: false, removePrefix: 'build/libs', sourceFiles: 'build/libs/*.jar')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
                }
            }
        }
    }
}

ย 

โœ”๏ธ ์„ฑ๊ณต์ ์œผ๋กœ ์‹คํ–‰๋˜์—ˆ๋Š”์ง€ ํŒŒ์ผ ํ™•์ธ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 38 42 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 39 21 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 40 53 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 41 07 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 41 12 แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 9 41 17
  • ์„ฑ๊ณต์ ์œผ๋กœ ์‹คํ–‰๋œ ๊ฒฐ๊ณผ๋‹ค. (EC2 ์ฝ˜์†”์—์„œ ps -ef | grep java ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๊ตฌ๋™์ด ์ž˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.)
  • ๋‹ค๋งŒ, ์‹คํ–‰ํ•˜๋‹ค 2๋ถ„๋’ค ์ข…๋ฃŒ๋œ๋‹ค. ๊ทธ์ „๊นŒ์ง€๋Š” ์—…๋กœ๋“œ๊ฐ€ ๊ณ„์† ์ง„ํ–‰์ค‘์ด์—ˆ๋‹ค.

=> ์ด์ œ Jenkins ์›น ์ฝ˜์†”์— ์ ‘์†ํ•ด build now๋ฅผ ๋ˆ„๋ฅด๋ฉด ํ”„๋กœ๊ทธ๋žจ์„ ์ž๋™ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐœํŒ์„ ๋งˆ๋ จํ–ˆ๋‹ค!

ย 

ย 

๐Ÿ“š 6. ๋นŒ๋“œ ์œ ๋ฐœํ•˜๊ธฐ

โœ”๏ธ github์—์„œ ์ œ๊ณตํ•˜๋Š” webhook

  • ํŠน์ •ํ•œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ, ํ•ด๋‹น ๋‚ด์šฉ์„ ๋“ฑ๋กํ•ด๋†“์€ api๋กœ ๋ณด๋‚ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ด๋‹ค.
  • ์ด ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜์—ฌ github์—์„œ ํŠน์ •ํ•œ ํ™œ๋™์ด ์ผ์–ด๋‚ฌ์„ ๋•Œ job์ด ์œ ๋ฐœ๋˜๋„๋ก ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

=> ์ด๋ฅผ ์ ์šฉํ•ด๋ณด๊ธฐ ์œ„ํ•ด PR์ด merge๋  ๋•Œ ์ž๋™์œผ๋กœ ๋นŒ๋“œ๊ฐ€ ์ผ์–ด๋‚˜๋„๋ก ์„ค์ •ํ•ด๋ณด์ž!

ย 

๐Ÿ’ก ์ฐธ๊ณ 
Github hook trigger for GITScm polling ์˜ต์…˜์€ freestyle์—์„œ build trigger๋กœ ๋งŽ์ด ์‚ฌ์šฉํ–ˆ์—ˆ๋‹ค.
ํ•˜์ง€๋งŒ, pipeline์—์„œ๋Š” ์ œ๋Œ€๋กœ ๋™์ž‘์‹œํ‚ค๊ธฐ ์–ด๋ ต๊ณ  ๋””ํ…Œ์ผํ•œ ์„ธํŒ…์„ ํ•  ์ˆ˜ ์—†๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ๋‹ค.

ย 

โœ”๏ธ ๋ฐฑ์—”๋“œ PR merge์—๋งŒ Jenkins๊ฐ€ ๋™์ž‘ํ•˜๋„๋ก ๋งŒ๋“ค์–ด๋ณด์ž!

์–ด๋–ป๊ฒŒ ํ•˜๋ฉด ๋ ๊นŒ?

=> Pull Request์˜ ๋ผ๋ฒจ์„ ๋ฐ”ํƒ•์œผ๋กœ ๋ฐฑ์—”๋“œ์™€ ํ”„๋ก ํŠธ์—”๋“œ PR์„ ๊ตฌ๋ถ„ํ•˜๋„๋ก ํ•ด๋ณด์ž!
=> ๋ฐฑ์—”๋“œ ๋ผ๋ฒจ์ด ๋ถ™์–ด ์žˆ๋Š” PR์ด ๋จธ์ง€ ๋˜์—ˆ์„ ๋•Œ๋งŒ ๋นŒ๋“œ๊ฐ€ ์ผ์–ด๋‚˜๋„๋ก ํ•ด๋ณด์ž!

ย 

โœ”๏ธ Generic Webhook Trigger ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-15 แ„‹แ…ฉแ„’แ…ฎ 11 09 07

ย 

ํŒŒ์ดํ”„๋ผ์ธ์˜ ์ƒ์„ธ๋‚ด์šฉ์—์„œ build triggers๋กœ ์ด๋™ํ•˜๋ฉด, generic webhook trigger๊ฐ€ ์ถ”๊ฐ€๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

๋ผ๊ณ  ํ–ˆ์ง€๋งŒ, ์ผ๋‹จ์€ ์‹œ๊ฐ„์ด ์—†์–ด

Github hook trigger for GITScm polling ์„ ์‚ฌ์šฉํ–ˆ๋‹ค. (์ถ”ํ›„ ๋ณ€๊ฒฝ๋  ์˜ˆ์ •)
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-01-16 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 12 06 21

ย 

ย 


์ฐธ๊ณ 

profile
"์•ผ, (์˜ค๋ฅ˜ ๋งŒ๋‚ฌ์–ด?) ๋„ˆ๋‘ (ํ•ด๊ฒฐ) ํ•  ์ˆ˜ ์žˆ์–ด"

0๊ฐœ์˜ ๋Œ“๊ธ€