-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
71 lines (60 loc) · 2.1 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
pipeline {
agent any
tools {
nodejs "nodejs12"
}
environment {
CI = 'true'
IMAGE = 'ghcr.io/zzuda/zuda-backend'
CONTAINER_NAME = 'zuda-backend'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Lint and Test') {
steps {
sh 'yarn'
sh 'yarn lint'
sh 'yarn test'
}
}
stage('Build') {
environment {
TAG = sh(returnStdout: true, script: "git tag --sort version:refname | tail -1").trim()
GH_USERNAME = credentials('GH_USERNAME')
GH_TOKEN = credentials('GH_TOKEN')
}
steps {
sh 'echo ${GH_TOKEN} | docker login ghcr.io -u ${GH_USERNAME} --password-stdin'
sh 'docker build -t ${IMAGE}:latest -t ${IMAGE}:${TAG} .'
sh 'docker push ${IMAGE}'
}
}
stage('Container cleanup') {
steps {
sh 'docker ps -q --filter "name=${CONTAINER_NAME}" | grep -q . && docker stop ${CONTAINER_NAME} && docker rm ${CONTAINER_NAME} || true'
sh 'docker ps -q --filter "name=zuda-db" | grep -q . && docker stop zuda-db && docker rm zuda-db || true'
sh 'docker ps -q --filter "name=zuda-mongo" | grep -q . && docker stop zuda-mongo && docker rm zuda-mongo || true'
}
}
stage('Deploy') {
steps {
sh 'docker-compose up -d'
}
}
}
post {
always {
cleanWs()
}
success {
discordSend title: '🚀 배포 성공!', description: '`zuda-backend` 배포를 성공하였습니다.', result: 'SUCCESS', link: currentBuild.absoluteUrl, webhookURL: env.DISCORD_WEBHOOK
}
failure {
discordSend title: '💥 배포 실패!', description: '`zuda-backend` 배포를 실패하였습니다.', result: 'FAILURE', link: currentBuild.absoluteUrl, webhookURL: env.DISCORD_WEBHOOK
}
}
}