-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
83 lines (77 loc) · 3.27 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
pipeline {
agent any
environment {
BACKEND_IMAGE = 'backend'
FRONTEND_IMAGE = 'frontend'
VITE_APP_BASE_URL = 'https://j11a206.p.ssafy.io/api/'
VITE_APP_SOCKET_URL = 'wss://j11a206.p.ssafy.io/omg'
}
stages {
stage('Backend Build') {
steps {
script {
echo '********** Backend Build Start **********'
dir('omg-back') {
sh 'docker build -t docker-image/$BACKEND_IMAGE .'
}
echo '********** Backend Build End **********'
}
}
}
stage('Frontend Build') {
steps {
script {
echo '********** Frontend Build Start **********'
dir('omg-front') {
sh 'pwd' // 현재 디렉토리 출력
sh 'ls -al' // 디렉토리 내 파일 목록 확인
// Frontend build with environment variables
sh """
docker build --no-cache \
--build-arg VITE_APP_BASE_URL=${VITE_APP_BASE_URL} \
--build-arg VITE_APP_SOCKET_URL=${VITE_APP_SOCKET_URL} \
-t docker-image/$FRONTEND_IMAGE .
"""
}
echo '********** Frontend Build End **********'
}
}
}
stage('Docker Compose Up') {
steps {
script {
echo '******** Docker Compose Start ************'
sh 'docker compose down' // 기존 컨테이너를 모두 중지 및 제거
sh 'docker rm -f frontend || true' // 이미 존재하는 컨테이너가 있다면 강제로 삭제
sh 'docker rm -f backend || true'
sh 'docker compose up -d' // 새로운 컨테이너 실행
echo '********** Docker Compose End ***********'
}
}
}
}
post {
success {
script {
def Author_ID = sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
def Author_Name = sh(script: "git show -s --pretty=%ae", returnStdout: true).trim()
mattermostSend (color: 'good',
message: "빌드 성공: ${env.JOB_NAME} #${env.BUILD_NUMBER} by ${Author_ID}(${Author_Name})\n(<${env.BUILD_URL}|Details>)",
endpoint: 'https://meeting.ssafy.com/hooks/ceutz8ibfbgm3mwbji6f7yeehy',
channel: 'jenkins'
)
}
}
failure {
script {
def Author_ID = sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
def Author_Name = sh(script: "git show -s --pretty=%ae", returnStdout: true).trim()
mattermostSend (color: 'danger',
message: "빌드 실패: ${env.JOB_NAME} #${env.BUILD_NUMBER} by ${Author_ID}(${Author_Name})\n(<${env.BUILD_URL}|Details>)",
endpoint: 'https://meeting.ssafy.com/hooks/ceutz8ibfbgm3mwbji6f7yeehy',
channel: 'jenkins'
)
}
}
}
}