-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
69 lines (58 loc) · 1.66 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
pipeline {
agent any
tools {
nodejs 'Node-20'
}
environment {
// 환경 변수 설정
DOCKER_TAG = "latest"
REPO_NAME = "sungwoo166/react-app"
CONTAINER_NAME = "react-web-app"
IMAGE_NAME = "${REPO_NAME}:${DOCKER_TAG}"
COMPOSE_FILE = '/var/jenkins_home/docker-compose.yml'
}
stages {
stage('Clone Repository') {
steps {
git branch: 'develop', url: "https://github.com/Woom-s-Land/wooms-frontend"
}
}
stage('Install Dependencies') {
steps {
sh 'npm install'
}
}
stage('Build React Project') {
steps {
sh 'npm run build'
}
}
stage('Docker Login') {
steps {
withCredentials([usernamePassword(credentialsId: 'docker-hub', passwordVariable: 'DOCKER_PWD', usernameVariable: 'DOCKER_USR')]) {
sh 'echo $DOCKER_PWD | docker login -u $DOCKER_USR --password-stdin'
}
}
}
stage('Build Docker Image') {
steps {
sh "docker build -t ${REPO_NAME}:${DOCKER_TAG} ."
}
}
stage('Push Docker Image') {
steps {
sh "docker push ${REPO_NAME}:${DOCKER_TAG}"
}
}
stage('Stop Existing Containers') {
steps {
sh 'docker-compose -f ${COMPOSE_FILE} down'
}
}
stage('Start New Containers') {
steps {
sh 'docker-compose -f ${COMPOSE_FILE} up -d'
}
}
}
}