Skip to content

Commit 3337b0c

Browse files
fix trigger bug & add slack notification
1 parent 60b6d6d commit 3337b0c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Jenkinsfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ def isManualTrigger() {
22
return currentBuild.getBuildCauses().any { cause -> cause._class == 'hudson.model.Cause$UserIdCause' }
33
}
44

5+
@Library('shared-library') _
6+
57
pipeline {
68

79
agent {
@@ -19,6 +21,17 @@ pipeline {
1921

2022
stages {
2123
stage('Read Version from pom.xml') {
24+
when {
25+
anyOf {
26+
allOf {
27+
branch 'master'
28+
triggeredBy 'UserIdCause' // Manual trigger on master
29+
}
30+
allOf {
31+
branch 'latest'
32+
}
33+
}
34+
}
2235
steps {
2336
dir('superstream-clients'){
2437
script {
@@ -120,6 +133,48 @@ pipeline {
120133
always {
121134
cleanWs()
122135
}
136+
success {
137+
script {
138+
if (env.GIT_BRANCH == 'latest') {
139+
sendSlackNotification('SUCCESS')
140+
notifySuccessful()
141+
}
142+
}
143+
}
144+
145+
failure {
146+
script {
147+
if (env.GIT_BRANCH == 'latest') {
148+
sendSlackNotification('FAILURE')
149+
notifyFailed()
150+
}
151+
}
152+
}
153+
aborted {
154+
script {
155+
if (env.BRANCH_NAME == 'latest') {
156+
sendSlackNotification('ABORTED')
157+
}
158+
// Get the build log to check for the specific exception and retry job
159+
AgentOfflineException()
160+
}
161+
}
123162
}
124163
}
125164

165+
def notifySuccessful() {
166+
emailext (
167+
subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
168+
body: """SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
169+
Check console output and connection attributes at ${env.BUILD_URL}""",
170+
171+
)
172+
}
173+
def notifyFailed() {
174+
emailext (
175+
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
176+
body: """FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
177+
Check console output at ${env.BUILD_URL}""",
178+
179+
)
180+
}

0 commit comments

Comments
 (0)