-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile - develop
68 lines (64 loc) · 2.35 KB
/
Jenkinsfile - develop
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
pipeline {
agent any
options {
skipDefaultCheckout()
}
environment {
// this credential needs to exist in Jenkins (https://jenkins.io/doc/book/using/using-credentials)
// and should contain the RocketChat Integration Token (https://rocket.chat/docs/administrator-guides/integrations/)
ROCKETCHAT_WEBHOOK_TOKEN = credentials('rocketchat_incoming_webhook_token')
}
stages {
stage('Building: public (develop branch)') {
steps {
script {
try {
notifyBuild("Building: ${env.JOB_NAME} ${env.BUILD_ID}", "YELLOW")
echo "Building: env.JOB_NAME=${env.JOB_NAME} env.BUILD_ID=${env.BUILD_ID}"
openshiftBuild bldCfg: 'angular-on-nginx-build-angular-app-build', showBuildLogs: 'true'
} catch (e) {
notifyBuild("BUILD ${env.JOB_NAME} ${env.BUILD_ID} FAILED", "RED")
error("Building: Failed: ${e}")
}
notifyBuild("Built ${env.JOB_NAME} ${env.BUILD_ID}", "GREEN")
echo "Building: Success"
}
}
}
stage('Deploying: public (develop branch)') {
steps {
script {
try {
notifyBuild("Deploying: ${env.JOB_NAME} ${env.BUILD_ID}", "YELLOW")
echo "Deploying: env.JOB_NAME=${env.JOB_NAME} env.BUILD_ID=${env.BUILD_ID}"
openshiftBuild bldCfg: 'angular-on-nginx-build', showBuildLogs: 'true'
} catch (e) {
notifyBuild("DEPLOYMENT ${env.JOB_NAME} ${env.BUILD_ID} FAILED", "RED")
error("Deploying: Failed: ${e}")
}
notifyBuild("Deployed ${env.JOB_NAME} ${env.BUILD_ID}", "GREEN")
echo "Deploying: Success"
}
}
}
}
}
def notifyBuild(String msg = '', String colour = '') {
if (colour == 'GREEN') {
colorCode = '#00FF00'
} else if (colour == 'YELLOW') {
colorCode = '#FFFF00'
} else if (colour == 'RED') {
colorCode = '#FF0000'
} else {
colorCode = '#000000' // black
}
String rocketChatMessage = "{ \"attachments\": [{ \"text\":\"${msg}\", \"color\":\"${colorCode}\" }] }"
String rocketChatWebHookURL = "https://chat.pathfinder.gov.bc.ca/hooks/${ROCKETCHAT_WEBHOOK_TOKEN}"
// Send notifications to RocketChat
try {
sh "curl -X POST -H 'Content-type: application/json' --data '${rocketChatMessage}' ${rocketChatWebHookURL}"
} catch (e) {
echo "Notify: Failed: ${e}"
}
}