-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
52 lines (44 loc) · 1.6 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
pipeline {
agent {
label 'sonic-build'
}
stages {
stage("Check for previous builds") {
steps {
print "GIT_AUTHOR_EMAIL:${GIT_AUTHOR_EMAIL}"
print "GIT_COMMITTER_EMAIL:${GIT_COMMITTER_EMAIL}"
print "OK"
}
}
}
post {
always {
sendSlackMessageStage()
script {
print "HAGAI"
}
} //always
} //post
}
def sendSlackMessageStage() {
script {
try {
//Get the commiter email out of the repo
COMMITER = sh (
script: 'git --no-pager show -s --format=\'%ce\'',
returnStdout: true
).trim()
print "COMMITER: ${COMMITER}"
//Get slack user id from email
USERID = slackUserIdFromEmail email: "${COMMITER}", botUser: true
RESULT = currentBuild.currentResult
if (RESULT == 'SUCCESS') messageColor="#BADA55" else messageColor="#FF2D00"
JOB_URL_SONIC = "${env.BUILD_URL}/display/redirect"
REBUILD_URL = "${env.BUILD_URL}rebuild/parameterized"
messageText = "[${RESULT}] UAT - ${currentBuild.displayName}, duration: ${currentBuild.durationString.replace(' and counting', '')}, <${JOB_URL_SONIC}|Job Url>, <${REBUILD_URL}|Rebuild>, commiter: ${COMMITER}"
slackSend channel:"@${USERID},jenkins_delivery", color: "${messageColor}", message: "${messageText}", botUser: true, username: 'jenkinsbot'
} catch (Exception e) {
print "Skipped slack step for message send"
}
} //script
}