Skip to content

Commit c6964fd

Browse files
authored
build: Create Jenkinsfile
1 parent 756a156 commit c6964fd

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

Jenkinsfile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
pipeline {
2+
agent any
3+
4+
environment {
5+
DISCORD_WEBHOOK = credentials('discord-webhook')
6+
}
7+
8+
tools {
9+
jdk 'OpenJDK17'
10+
}
11+
12+
stages {
13+
stage('Checkout') {
14+
steps {
15+
checkout scm
16+
}
17+
}
18+
19+
stage('Build MySQL Service') {
20+
steps {
21+
script {
22+
// Docker로 MySQL 컨테이너 띄우기 (jenkins 서버에 Docker가 설치되어 있어야 함)
23+
sh '''
24+
docker run -d \
25+
--name mysql-ci \
26+
-e MYSQL_DATABASE=${DB_NAME} \
27+
-e MYSQL_ROOT_PASSWORD=root \
28+
-e MYSQL_USER=homeaid_user \
29+
-e MYSQL_PASSWORD=${DB_PASSWORD} \
30+
-p 3306:3306 \
31+
--health-cmd="mysqladmin ping -h localhost --silent" \
32+
--health-interval=10s \
33+
--health-timeout=5s \
34+
--health-retries=3 \
35+
mysql:latest
36+
37+
# DB 준비 대기 (최대 60초)
38+
for i in {1..12}; do
39+
if docker exec mysql-ci mysqladmin ping -h localhost --silent; then
40+
echo "MySQL is ready!"
41+
break
42+
fi
43+
echo "Waiting for MySQL..."
44+
sleep 5
45+
done
46+
'''
47+
}
48+
}
49+
}
50+
51+
stage('Build and Test') {
52+
steps {
53+
sh 'chmod +x ./gradlew'
54+
withEnv([
55+
"DB_DRIVER=${DB_DRIVER}",
56+
"DB_HOST=${DB_HOST}",
57+
"DB_PORT=${DB_PORT}",
58+
"DB_NAME=${DB_NAME}",
59+
"DB_USERNAME=${DB_USERNAME}",
60+
"DB_PASSWORD=${DB_PASSWORD}"
61+
]) {
62+
sh './gradlew clean build'
63+
}
64+
}
65+
}
66+
}
67+
68+
post {
69+
success {
70+
script {
71+
def message = """{
72+
"embeds": [{
73+
"title": "✅ CI 성공",
74+
"description": "**📦 Repository:** `${env.JOB_NAME}`\\n**🌿 Branch:** `${env.BRANCH_NAME}`\\n**👤 Triggered by:** `${env.BUILD_USER}`\\n[🔗 Jenkins 로그 확인하기](${env.BUILD_URL})",
75+
"color": 5763719
76+
}],
77+
"content": "✅ CI 통과: `${env.BRANCH_NAME}` 브랜치입니다!"
78+
}"""
79+
sh """
80+
curl -H "Content-Type: application/json" \
81+
-X POST \
82+
-d '${message}' \
83+
${DISCORD_WEBHOOK}
84+
"""
85+
}
86+
}
87+
failure {
88+
script {
89+
def message = """{
90+
"embeds": [{
91+
"title": "❌ CI 실패",
92+
"description": "**📦 Repository:** `${env.JOB_NAME}`\\n**🌿 Branch:** `${env.BRANCH_NAME}`\\n**👤 Triggered by:** `${env.BUILD_USER}`\\n[🔗 Jenkins 로그 확인하기](${env.BUILD_URL})",
93+
"color": 16711680
94+
}],
95+
"content": "❗ CI 실패 발생: `${env.BRANCH_NAME}` 브랜치 확인해주세요!"
96+
}"""
97+
sh """
98+
curl -H "Content-Type: application/json" \
99+
-X POST \
100+
-d '${message}' \
101+
${DISCORD_WEBHOOK}
102+
"""
103+
}
104+
}
105+
always {
106+
// Clean up MySQL container
107+
sh '''
108+
docker stop mysql-ci || true
109+
docker rm mysql-ci || true
110+
'''
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)