-
Notifications
You must be signed in to change notification settings - Fork 2
/
backend-Jenkinsfile
65 lines (62 loc) · 2.73 KB
/
backend-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
// 백엔드용 젠킨스 파일
pipeline {
agent any
stages {
stage('remove previous docker container and image') {
steps{
echo 'Remove Docker Process and Image'
sh '''if [ "$(docker ps -a -q -f name=docker-backend)" ]; then
docker stop docker-backend
if [ "$(docker ps -aq -f status=exited -f name=docker-backend)" ]; then
docker rm docker-backend
docker rmi image-backend
fi
fi'''
}
}
stage('copy yml before build') {
steps {
withCredentials([file(credentialsId: 'application-credentials', variable: 'defaultConfigFile'),
file(credentialsId: 'application-oauth-credentials', variable: 'oauthConfigFile'),
file(credentialsId: 'application-secret-credentials', variable: 'secretConfigFile'),
file(credentialsId: 'application-datasource-credentials', variable: 'datasourceConfigFile')]) {
script {
sh 'chmod 755 $defaultConfigFile'
sh 'chmod 755 $oauthConfigFile'
sh 'chmod 755 $secretConfigFile'
sh 'chmod 755 $datasourceConfigFile'
sh 'cp -f -R $defaultConfigFile backend/src/main/resources/application.yml'
sh 'cp -f -R $oauthConfigFile backend/src/main/resources/application-oauth.yml'
sh 'cp -f -R $secretConfigFile backend/src/main/resources/application-secret.yml'
sh 'cp -f -R $datasourceConfigFile backend/src/main/resources/application-datasource.yml'
}
}
}
}
stage('build gradle') {
steps {
echo 'Build Gradle'
dir('backend') {
sh "chmod +x ./gradlew"
sh "./gradlew clean build -x check --parallel"
}
echo 'Docker Build'
sh "docker build --build-arg JAR_FILE=backend/build/libs/voda-0.0.1-SNAPSHOT.jar -t image-backend ."
echo 'Docker Run'
sh "docker run -d -p 8080:8080 --name docker-backend image-backend"
}
post {
success {
echo "build success"
// 빌드가 성공했을 때 GitLab에 성공 상태를 알립니다.
updateGitlabCommitStatus name: 'build', state: 'success'
}
failure {
echo "build failed"
// 빌드가 실패했을 때 GitLab에 실패 상태를 알립니다.
updateGitlabCommitStatus name: 'build', state: 'failed'
}
}
}
}
}