-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfileTelegramFailure
62 lines (56 loc) · 2.15 KB
/
JenkinsfileTelegramFailure
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
pipeline {
agent any
environment {
// Telegram configre
TOKEN = credentials('telegramToken')
CHAT_ID = credentials('telegramChatid')
// Telegram Message Pre Build
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 = "--------------------------------------------------------------"
TEXT_PRE_BUILD = "${TEXT_BREAK}\n${GIT_INFO}\n${JOB_NAME} is Building"
// Telegram Message Success and Failure
TEXT_SUCCESS_BUILD = "${JOB_NAME} is Success"
TEXT_FAILURE_BUILD = "${JOB_NAME} is Failure"
}
stages {
stage('Pre-Build') {
steps {
sh "curl --location --request POST 'https://api.telegram.org/bot${TOKEN}/sendMessage' --form text='${TEXT_PRE_BUILD}' --form chat_id='${CHAT_ID}'"
}
}
stage('Build') {
steps {
echo 'Building...'
echo 'Running docker build...'
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Push') {
steps {
echo 'Pushing...'
echo 'Running docker push...'
sh "kubectl get pod"
}
}
}
post {
success {
script{
sh "curl --location --request POST 'https://api.telegram.org/bot${TOKEN}/sendMessage' --form text='${TEXT_SUCCESS_BUILD}' --form chat_id='${CHAT_ID}'"
}
}
failure {
script{
sh "curl --location --request POST 'https://api.telegram.org/bot${TOKEN}/sendMessage' --form text='${TEXT_FAILURE_BUILD}' --form chat_id='${CHAT_ID}'"
}
}
}
}