-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
83 lines (83 loc) · 3.35 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 {
REGISTRY_URL = 'gcu-lucky7-dev.kr-central-2.kcr.dev'
REGISTRY_CREDENTIALS_ID = 'kakao-cloud-credentials'
IMAGE_NAME = 'lucky7-cr/auth-service'
}
stages {
stage('Checkout') {
steps {
git branch: 'main', credentialsId: 'github-signin', url: 'https://github.com/KEA-Lucky7/MOABOA-BE-AuthService.git'
}
}
stage('Build') {
steps {
script {
sh 'chmod +x gradlew'
sh './gradlew clean build'
}
}
}
stage('Build Docker Image and Push') {
steps {
script {
docker.withRegistry("http://${env.REGISTRY_URL}", "${env.REGISTRY_CREDENTIALS_ID}") {
def app = docker.build("${env.REGISTRY_URL}/${env.IMAGE_NAME}")
app.push("${env.BUILD_ID}")
}
}
}
}
stage('Update Helm Values YAML') {
steps {
script {
git branch: 'main', credentialsId: 'github-signin', url: 'https://github.com/KEA-Lucky7/MOABOA-GitOps.git'
sh """
sed -i 's|tag: .*|tag: ${env.BUILD_ID}|' charts/auth-service/values.yaml
"""
withCredentials([usernamePassword(credentialsId: 'github-signin', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh """
git config user.email "[email protected]"
git config user.name "wcorn"
git add charts/auth-service/values.yaml
git commit -m "[UPDATE] auth service image tag ${env.BUILD_ID}"
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/KEA-Lucky7/MOABOA-GitOps.git main
"""
}
}
}
}
stage('Cleanup') {
steps {
sh 'rm -rf *'
}
}
}
post {
success {
withCredentials([string(credentialsId: 'discord-webhook', variable: 'DISCORD')]) {
discordSend description: """
제목 : ${currentBuild.displayName}
결과 : ${currentBuild.result}
실행 시간 : ${currentBuild.duration / 1000}s
""",
link: env.BUILD_URL, result: currentBuild.currentResult,
title: "${env.JOB_NAME} : ${currentBuild.displayName} 성공",
webhookURL: "$DISCORD"
}
}
failure {
withCredentials([string(credentialsId: 'Discord-Webhook', variable: 'DISCORD')]) {
discordSend description: """
제목 : ${currentBuild.displayName}
결과 : ${currentBuild.result}
실행 시간 : ${currentBuild.duration / 1000}s
""",
link: env.BUILD_URL, result: currentBuild.currentResult,
title: "${env.JOB_NAME} : ${currentBuild.displayName} 실패",
webhookURL: "$DISCORD"
}
}
}
}