Intro::
๋ก์ปฌ์์ jenkins๋ฅผ ์ฌ์ฉํด์ ci/cd ๋ฅผ ๊ตฌํํ๋ ์์ ์
๋๋ค.
1.
jenkins ๋์ปค ์คํ
2.
jenkins plugin ์ค์น
a.
docker ํ๋ฌ๊ทธ์ธ์ ๋ฐ๋ก ์ค์นํจ
3.
์นํ
์ค
pipeline
pipeline {
agent any
environment {
// ๋์ปค ์ด๋ฏธ์ง ํ๊ทธ๋ฅผ ๋ก์ปฌ์์ ๊ด๋ฆฌํ๊ธฐ ์ํ ๋ณ์ ์ค์
APP1_IMAGE = "echo:latest"
APP2_IMAGE = "time:latest"
}
stages {
stage('Git Config Setting') {
steps {
sh 'git config --global http.sslVerify false'
}
}
stage('Checkout') {
steps {
// GitHub ๋ชจ๋
ธ๋ ํฌ์์ main ๋ธ๋์น ์ฒดํฌ์์
git branch: 'main', url: 'https://github.com/SONGS4RI/jenkins-example.git'
}
}
stage('Build echo') {
steps {
sh "docker build -f echo/Dockerfile -t ${APP1_IMAGE} ."
echo "App1 ์ด๋ฏธ์ง ๋น๋ ์๋ฃ: echo:${APP1_IMAGE}"
}
}
stage('Build time') {
steps {
sh "docker build -f time/Dockerfile -t ${APP2_IMAGE} ."
echo "App2 ์ด๋ฏธ์ง ๋น๋ ์๋ฃ: time:${APP2_IMAGE}"
}
}
stage('Deploy') {
steps {
echo '๋ฐฐํฌ ๋จ๊ณ: ๋์ปค ์ปจํ
์ด๋ ์คํ'
sh "docker run -d --name echo -p 8080:8080 ${APP1_IMAGE}"
sh "docker run -d --name time -p 8081:8080 ${APP2_IMAGE}"
}
}
}
post {
always {
echo '๋น๋ ์๋ฃ ํ ์์
๊ณต๊ฐ ์ ๋ฆฌ'
cleanWs()
}
success {
echo 'ํ์ดํ๋ผ์ธ์ด ์ฑ๊ณต์ ์ผ๋ก ์๋ฃ๋์์ต๋๋ค.'
}
failure {
echo 'ํ์ดํ๋ผ์ธ ์คํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์์ต๋๋ค.'
}
}
}
YAML
๋ณต์ฌ
๋ฐฉ๋ฒ 1: GitHub Webhook ์ค์ (๊ฐ์ฅ ์ค์๊ฐ & ์ถ์ฒ)
Jenkins๊ฐ ์ธ๋ถ ์์ฒญ์ ๋ฐ์ ๋น๋ํ๋๋ก ์ค์ ํ๋ ๋ฐฉ์
1. GitHub ์ ์ฅ์ โ Settings โ Webhooks
โข
Payload URL:
http://<Jenkins์๋ฒ์ฃผ์>:ํฌํธ/github-webhook/
์: http://localhost:18081/github-webhook/ ๋๋ http://jenkins.mycompany.com/github-webhook/
โข
Content type:
application/json
โข
Trigger:
โ Just the push event ์ฒดํฌ
2. Jenkins์์ ํ๋ก์ ํธ ์ค์
โข
"GitHub hook trigger for GITScm polling" ์ฒดํฌ
โ ํ๋ก์ ํธ ์ค์ > Build Triggers ํญ๋ชฉ์์