forked from bcgov/mem-mmti-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
85 lines (78 loc) · 2.91 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Edit your app's name below
def APP_NAME = 'mem-mmt'
// Edit your environment TAG names below
def TAG_NAMES = ['dev', 'test', 'prod']
// You shouldn't have to edit these if you're following the conventions
def NGINX_BUILD_CONFIG = 'nginx-runtime'
def BUILD_CONFIG = APP_NAME + '-build'
def IMAGESTREAM_NAME = 'angular-on-nginx-build'
node {
try {
notifyBuild('STARTED')
stage('build chained angular app build'){
notifyBuild('STARTED')
openshiftBuild(bldCfg: 'angular-on-nginx-build-build-angular-app-build', showBuildLogs: 'true')
}
stage('build angular-on-nginx-build-build') {
echo "Building: angular-on-nginx-build-build"
openshiftBuild bldCfg: 'angular-on-nginx-build-build', showBuildLogs: 'true'
}
stage('deploy-' + TAG_NAMES[0]) {
openshiftTag destStream: IMAGESTREAM_NAME, verbose: 'true', destTag: TAG_NAMES[0], srcStream: IMAGESTREAM_NAME, srcTag: 'latest'
notifyBuild('DEPLOYED:DEV')
}
stage('deploy-' + TAG_NAMES[1]) {
try {
timeout(time: 2, unit: 'MINUTES') {
input "Deploy to " + TAG_NAMES[1] + "?"
openshiftTag destStream: IMAGESTREAM_NAME, verbose: 'true', destTag: TAG_NAMES[1], srcStream: IMAGESTREAM_NAME, srcTag: 'dev'
notifyBuild('DEPLOYED:TEST')
}
} catch (e) {
notifyBuild('DEPLOYMENT:TEST ABORTED')
}
}
stage('deploy-' + TAG_NAMES[2]) {
try {
timeout(time: 2, unit: 'MINUTES') {
input "Deploy to " + TAG_NAMES[2] + "?"
openshiftTag destStream: IMAGESTREAM_NAME, verbose: 'true', destTag: TAG_NAMES[2], srcStream: IMAGESTREAM_NAME, srcTag: 'test'
notifyBuild('DEPLOYED:PROD')
}
} catch (e) {
notifyBuild('DEPLOYMENT:PROD ABORTED')
}
}
} catch (e) {
// If there was an exception thrown, the build failed
currentBuild.result = "FAILED"
throw e
} finally {
// Success or failure, always send notifications
notifyBuild(currentBuild.result)
}
}
def notifyBuild(String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'
// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
def details = """<p>STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>"""
// Override default values based on build status
if (buildStatus == 'STARTED' || buildStatus.startsWith("DEPLOYMENT")) {
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESSFUL' || buildStatus.startsWith("DEPLOYED")) {
color = 'GREEN'
colorCode = '#00FF00'
} else {
color = 'RED'
colorCode = '#FF0000'
}
// Send notifications
slackSend (color: colorCode, message: summary)
}