forked from Peeper-CAU/Peeper_BE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
66 lines (58 loc) · 2.53 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
pipeline {
agent any
environment {
TELEGRAM_BOT_ID = credentials("telegram-botid-yymin1022")
TELEGRAM_CHAT_ID = credentials("telegram-chatid-yymin1022")
CURRENT_BUILD_NUMBER = "${currentBuild.number}"
GIT_MESSAGE = sh(returnStdout: true, script: "git log -n 1 --format=%s ${GIT_COMMIT}").trim()
GIT_AUTHOR = sh(returnStdout: true, script: "git log -n 1 --format=%ae ${GIT_COMMIT}").trim()
GIT_COMMIT_SHORT = sh(returnStdout: true, script: "git rev-parse --short ${GIT_COMMIT}").trim()
GIT_INFO = "Branch(Version): ${GIT_BRANCH}\nLast Message: ${GIT_MESSAGE}\nAuthor: ${GIT_AUTHOR}\nCommit: ${GIT_COMMIT_SHORT}"
TEXT_BREAK = "New Build Task Started !!"
TEXT_PRE_BUILD = "${TEXT_BREAK}\n${GIT_INFO}\n${JOB_NAME}\n\nBuild가 시작되었습니다."
TEXT_SUCCESS_BUILD = "${JOB_NAME} Build가 성공하였습니다."
TEXT_FAILURE_BUILD = "${JOB_NAME} Build가 실패하였습니다."
}
stages {
stage("Set Variable") {
steps {
script {
DOCKERHUB_CREDENTIAL = "dockerhub-yymin1022"
DOCKER_IMAGE_NAME = "peeper-be"
DOCKER_IMAGE_STORAGE = "yymin1022"
DOCKER_IMAGE_TAG = "release_1"
sh "curl --location --request POST 'https://api.telegram.org/bot${TELEGRAM_BOT_ID}/sendMessage' --form text='${TEXT_PRE_BUILD}' --form chat_id='${TELEGRAM_CHAT_ID}'"
}
}
}
stage("Build Docker Image") {
steps {
script {
image = docker.build("${DOCKER_IMAGE_STORAGE}/${DOCKER_IMAGE_NAME}")
}
}
}
stage("Push Docker Image to Dockerhub") {
steps {
script {
docker.withRegistry("", DOCKERHUB_CREDENTIAL) {
image.push("$DOCKER_IMAGE_TAG")
image.push("latest")
}
}
}
}
}
post {
success {
script{
sh "curl --location --request POST 'https://api.telegram.org/bot${TELEGRAM_BOT_ID}/sendMessage' --form text='${TEXT_SUCCESS_BUILD}' --form chat_id='${TELEGRAM_CHAT_ID}'"
}
}
failure {
script{
sh "curl --location --request POST 'https://api.telegram.org/bot${TELEGRAM_BOT_ID}/sendMessage' --form text='${TEXT_FAILURE_BUILD}' --form chat_id='${TELEGRAM_CHAT_ID}'"
}
}
}
}