-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
69 lines (65 loc) · 2.11 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
pipeline {
environment {
GIT_CREDS = credentials('345c79bc-9def-4981-94b5-d8190fdd2304') // as-ci-user.gen
WEBEX_ROOM = 'Y2lzY29zcGFyazovL3VzL1JPT00vZTMxNTUzZjAtZDNiMS0xMWViLWJjNzktMTUxMzcwZjZlOTYz' // Sastre - CICD Notifications
WEBEX_CREDS = '16fdd237-afe3-4d7f-9fe5-7bde6d1275e0' // [email protected]
}
agent { label "AMER-REGION" }
stages {
stage("Build App") {
steps {
echo "Build"
}
}
stage("Code Quality Test") {
steps {
echo "Code Quality"
}
}
stage("Deploy to Staging") {
when {
anyOf {
buildingTag()
branch 'master'
}
beforeAgent true
}
steps {
echo "Deploy to Staging"
}
}
}
post {
always {
echo 'Cleanup'
}
success {
sendNotifications('success', WEBEX_ROOM, WEBEX_CREDS)
}
unstable {
sendNotifications('unstable', WEBEX_ROOM, WEBEX_CREDS)
}
failure {
sendNotifications('failure', WEBEX_ROOM, WEBEX_CREDS)
}
}
}
def sendNotifications(String status, String room, String creds) {
def GIT_COMMIT = sh (label: "Get git commit ID", script: "git rev-parse HEAD || true", returnStdout: true).trim()
def AUTHOR = sh (label: "Get git commit Author", script: "git show -s --pretty=\"%an <%ae>\" ${GIT_COMMIT} || true", returnStdout: true).trim()
if (status == 'success') {
icon = "✅"
} else {
icon = "❌"
}
msg = "${icon} **Build ${env.BUILD_ID} ${status}** <br/> **Jenkins Job**: [${env.JOB_NAME}](${env.BUILD_URL}) <br/> **Change Author**: ${AUTHOR} <br/> **Git Branch**: ${env.BRANCH_NAME} <br/> **Git Commit**: ${GIT_COMMIT} <br/> **GitHub URL**: ${GIT_URL} <br/>"
sparkSend (
credentialsId: creds,
failOnError: false,
messageType: 'markdown',
spaceList: [[
spaceId: room
]],
message: msg
)
}