-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
79 lines (67 loc) · 2.03 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
pipeline {
agent any
tools {
jdk ("jdk22")
}
environment {
// 환경 변수 설정
DOCKER_TAG = "latest"
REPO_NAME = "sungwoo166/spring-app"
CONTAINER_NAME = "springboot-web-service"
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-backend"
}
}
stage('application.properties 설정'){
steps{
withCredentials([file(credentialsId: 'application-auth.properties', variable: 'properties')]) {
script {
sh 'cp $properties src/main/resources/application-auth.properties'
}
}
}
}
stage('Prepare Environment') {
steps {
sh 'chmod +x ./gradlew'
}
}
stage('Build Project') {
steps {
sh './gradlew clean 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'
}
}
}
}