๐ Jenkins๋?
Jenkins๋?
Jenkins๋ ์คํ์์ค ๊ธฐ๋ฐ์ CI/CD(Continuous Integration / Continuous Deployment) ์๋ํ ๋๊ตฌ
โ๏ธ 1. Jenkins์ ์ญํ
- CI (Continuous Integration, ์ง์์ ํตํฉ)
โ ๊ฐ๋ฐ์๊ฐ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ๋ฉด ์๋์ผ๋ก ๋น๋ ๋ฐ ํ
์คํธ๋ฅผ ์คํํ์ฌ ์ฝ๋์ ํ์ง์ ์ ์ง
- CD (Continuous Deployment/Delivery, ์ง์์ ๋ฐฐํฌ/์ ๋ฌ)
โ ํ
์คํธ๋ฅผ ํต๊ณผํ ์ฝ๋๋ฅผ ์๋์ผ๋ก ๋ฐฐํฌํ์ฌ ์๋น์ค์ ๋ฐฐํฌ๋ฅผ ์ํํ๊ฒ ์งํ
โ๏ธ 2. Jenkins์ ์ฃผ์ ๊ธฐ๋ฅ
- ์๋ ๋น๋: GitHub, GitLab, Bitbucket ๋ฑ์ ์ฝ๋ ์ ์ฅ์์์ ๋ณ๊ฒฝ ์ฌํญ์ด ๊ฐ์ง๋๋ฉด ์๋์ผ๋ก ๋น๋ ์คํ
- ์๋ ํ
์คํธ: ์ฝ๋ ๋ณ๊ฒฝ์ด ๋ฐ์ํ๋ฉด ์ง์ ๋ ํ
์คํธ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ์ฌ ์ค๋ฅ ์ฌ๋ถ๋ฅผ ํ์ธ
- ๋ฐฐํฌ ์๋ํ: ํ
์คํธ๋ฅผ ํต๊ณผํ ์ ํ๋ฆฌ์ผ์ด์
์ ์๋ฒ์ ์๋ ๋ฐฐํฌ (Docker, Kubernetes, AWS ๋ฑ ์ฐ๋ ๊ฐ๋ฅ)
- ํ๋ฌ๊ทธ์ธ ์ง์: 1,800๊ฐ ์ด์์ ํ๋ฌ๊ทธ์ธ์ ์ ๊ณตํ์ฌ ๋ค์ํ ํ๊ฒฝ๊ณผ ํตํฉ ๊ฐ๋ฅ
- ์น UI ์ ๊ณต: ๋ธ๋ผ์ฐ์ ์์ ์ฝ๊ฒ ๊ด๋ฆฌ ๊ฐ๋ฅ
โ๏ธ 3. Jenkins ๋์ ๊ณผ์
- ๊ฐ๋ฐ์๊ฐ ์ฝ๋๋ฅผ ํธ์ (GitHub, GitLab ๋ฑ)
- Jenkins๊ฐ ๋ณ๊ฒฝ ์ฌํญ์ ๊ฐ์งํ์ฌ ๋น๋ ์คํ
- ์ฝ๋๊ฐ ์ ์์ ์ผ๋ก ๋์ํ๋์ง ํ
์คํธ ์ํ
- ํ
์คํธ ํต๊ณผ ์ ๋ฐฐํฌ ์๋ํ ์ํ
์ฌ์ฉ์์1
ex) GitHub + Docker + AWS ๋ฐฐํฌ ์๋ํ
1. GitHub์์ ์ฝ๋๊ฐ ๋ณ๊ฒฝ๋๋ฉด Jenkins๊ฐ ๊ฐ์ง
2. ๋ณ๊ฒฝ๋ ์ฝ๋๋ฅผ ๊ฐ์ ธ์์ Docker ์ด๋ฏธ์ง๋ฅผ ๋น๋
3. ๋น๋ํ ์ด๋ฏธ์ง๋ฅผ Docker Hub์ ํธ์
4. AWS ์๋ฒ์์ ์๋ก์ด ์ปจํ
์ด๋๋ก ๋ฐฐํฌ
์ฌ์ฉ์์2
ex) ์ ํจ์ค์ CI/CD ๊ณผ์

1. ๋ก์ปฌ์์ ๊ฐ๋ฐ์๊ฐ ๊ฐ๋ฐํํ ๊ณต์ ๋ ํฌ์งํ ๋ฆฌ์ ์ปค๋ฐ ๋ฐ ํธ์
2. ์ ํจ์ค๊ฐ ์ด๋ฅผ ์ธ์งํ์ฌ ๋ณ๊ฒฝ๋ ์์ค์ฝ๋์ ๊ธฐ์กด์ฝ๋์ ํจ๊ป ๋น๋ ๋ฐ ํ
์คํธ
3. ๋น๋๊ฐ ์ฑ๊ณตํ ๊ฒฝ์ฐ ๋น๋ํ ํ์ผ์ ๋ฐฐํฌ ์๋ฒ๋ก ์ ์ก
4. ๋ง์ฝ ๋น๋ ๋ฐ ํ
์คํธ๋ฅผ ์คํจํ ๊ฒฝ์ฐ ๋ก๊ทธ๋ฅผ ๋จ๊ธฐ๊ณ ์ข
๋ฃ
โ๏ธ 4. Jenkins์ ํ์ดํ๋ผ์ธ
Pipeline
- ์ฐ์์ ์ธ ์์
๋ค์ ์ ํจ์ค์์ ํ๋์ ํ์ดํ๋ผ์ธ(์์
)์ผ๋ก ๋ฌถ์ด์ ๊ด๋ฆฌํ ์ ์๊ฒ ๋ง๋๋ ํ๋ฌ๊ทธ์ธ์ด๋ค.
- ์ ํจ์ค์ Pipeline์ ์์ฑํ๋๋ฐ Declarative, Scripted ๋ฐฉ์์ด ์๋ค. ์ด ๋๊ฐ์ง๋ ๋ฌธ๋ฒ์ ์ธ ์ฐจ์ด์ ์ด ์๋ค.
- Declarative๋ฐฉ์์ด Scripted๋ฐฉ์๋ณด๋ค ๋ ํ๋ถํ ๊ตฌ๋ฌธ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ฉฐ ๊ฐํธํ๊ฒ ์์ฑํ ์ ์๋ค.
Jenkins Pipeline์ ์ฃผ์ํญ๋ชฉ
-
Pipeline
- ๋น๋, ํ
์คํธ, ๋ฐฐํฌ ๋จ๊ณ๋ฅผ ํฌํจํ๋ ์ ์ฒด ๋น๋ ํ๋ก์ธ์ค๋ฅผ ์ ์ํ๋ค.
- ์ ์ธํ ํ์ดํ๋ผ์ธ(Declarative Pipeline) ๊ตฌ๋ฌธ์ ํต์ฌ ๋ถ๋ถ
Jenkinsfile์ ์์ ์ง์ ์ ์ ์ธ
-
Node
- ์คํฌ๋ฆฝํธํ ํ์ดํ๋ผ์ธ ๊ตฌ๋ฌธ์ ํต์ฌ ๋ถ๋ถ
Jenkinsfile์ ์์ ์ง์ ์ ์ ์ธ
-
Stage
- ์ ์ฒด ํ์ดํ๋ผ์ธ ๋จ๊ณ๋ฅผ ํตํด ์ํ๋๋ ์์
์ ํ์ ์งํฉ์ ์๋ฏธํ๋ค.
ex) jenkins ํ์ดํ๋ผ์ธ์ ๋น๋->ํ
์คํธ->๋ฐฐํฌ๋ผ ํ๋ค๋ฉด ๋น๋,ํ
์คํธ,๋ฐฐํฌ๊ฐ ๊ฐ Stage๋ฅผ ์๋ฏธํ๋ค.
-
Step
- ํ๋์
stage์์ ์์
์ ์ ์ํ๋ ๋ถ๋ถ
์ ์ธํ ํ์ดํ๋ผ์ธ(Declarative Pipeline) ๋ฌธ๋ฒ
Jenkinsfile์ ์์ฑํ๋ ๋ฌธ๋ฒ์ด๋ค. Groovy๋ฌธ๋ฒ๊ณผ ๋น์ทํ์ง๋ง ์ฝ๊ฐ์ ์ฐจ์ด์ ์ด ์๋ค.
์ ์ธํ ํ์ดํ๋ผ์ธ ๋ฌธ๋ฒ์ ์ธํฐ๋ท์ ๊ฒ์ํด๋ณด๋ฉด ์ ๋์ค๊ธฐ ๋๋ฌธ์ ํฐํ์ ๊ฐ๋
์ ์ ๋ฆฌํ ๊ฒ์ด๋ค.
//Jenkinsfile
pipeline {
agent any //Agent Sections
stages { //Stages Sections
stage('Prepare') { //Steps
agent any
steps {
...
}
post { //Post Section
failure{
error "Fail Cloned Repository"
}
}
}
stage('Build') {
agent any
steps{
...
}
post{
failure{
error 'Fail Build'
}
}
}
}
}
- Pipeline์ Sections์ ๊ตฌ์ฑ - Sections์ ์๋์ ํญ๋ชฉ๋ค์ด ํฌํจ๋๋ค.
- Agent Section: ์ฌ๋ฌ slave๋ฅผ ๋๊ณ ์์
์ ํ ๋ ์ด๋ค ์ ํจ์ค๊ฐ ์ผ์ ํ ์ง ์ ์
- Post Section: ๊ฐ ์คํ
์ด์ง๊ฐ ๋๋ํ ํ์ ์กฐ์น๊ธฐ๋ฅ์ ์ ์ (ex.Success, Failure, always, cleanup)
- Stages Section: ์ด๋ค ์ผ์ ์ฒ๋ฆฌํ ๊ฒ์ธ๊ฐ์ ๋ํ Stage ์ ์(ex. git clone, build, test, devlop)
- Steps: ์คํ
์ด์ง์์์ ์คํํ ์์
์ ์ ์
- Declaratives
: Environ ment (ํ์ดํ๋ผ์ธ ๋ฐ stage scope์ ํ๊ฒฝ๋ณ์ ์ค์ )
: Parameter (ํ์ดํ๋ผ์ธ ์คํ์์ ๋ฐ์ ํ๋ผ๋ฏธํฐ)
: Triggers (์ด๋ค ํํ๋ก ํธ๋ฆฌ๊ฑฐ ๋๋์ง ์ ์)
: When (์ธ์ ์คํ๋๋์ง ์ ์)
โ๏ธ 5. Jenkins์ ์ฅ์
- ์คํ์์ค: ๋ฌด๋ฃ๋ก ์ฌ์ฉ ๊ฐ๋ฅ
- ์๋ํ: ๋ฐ๋ณต์ ์ธ ๋น๋, ํ
์คํธ, ๋ฐฐํฌ ๊ณผ์ ์ ์๋ํ
- ์ ์ฐํ ํ์ฅ์ฑ: ๋ค์ํ ํ๋ฌ๊ทธ์ธ ์ง์
- ๋ค์ํ ํ๊ฒฝ ์ง์: Linux, Windows, macOS, Docker, Kubernetes ๋ฑ
์์ฝ
- Jenkins๋ CI/CD ์๋ํ๋ฅผ ์ํ ๊ฐ๋ ฅํ ๋๊ตฌ์ด๋ฉฐ, ๋ค์ํ ํ๋ฌ๊ทธ์ธ๊ณผ ํ์ฅ์ฑ์ ์ ๊ณตํ์ฌ DevOps ํ๊ฒฝ ๊ตฌ์ถ์ ํ์์ ์ธ ์ญํ ์ ํ๋ค.
โ๏ธ 6. ๊ทธ๋์ ์ธ์ ์ฌ์ฉํด?
- CI/CD ํ๊ฒฝ์ ์ง์ ๊ตฌ์ถํ๊ณ ์ถ์ ๋
- ์ฌ๋ฌ ๊ฐ๋ฐ ํ๋ก์ ํธ๋ฅผ ํ ๊ณณ์์ ๊ด๋ฆฌํ ๋
์ฐธ๊ณ ์๋ฃ
https://velog.io/@rnqhstlr2297/Jenkins-%EA%B0%9C%EB%85%90%EA%B3%BC-%EC%82%AC%EC%9A%A9
https://narup.tistory.com/179
https://narup.tistory.com/202?category=1023381
https://wlsdn3004.tistory.com/63