-
Notifications
You must be signed in to change notification settings - Fork 50
/
Jenkinsfile
162 lines (142 loc) · 3.51 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
String buildVersion = env.BUILD_NUMBER
try {
String gitCommitId
stage('Checkout') {
node {
sh "oc project ${env.PROJECT_NAME}"
checkout scm
stash includes: 'openshift/*.sh', name: 'scripts'
String gitCommitNum = sh(returnStdout: true, script: "git rev-list HEAD --count").trim()
String gitShortId = sh(returnStdout: true, script: "git rev-parse --short HEAD").trim()
buildVersion = gitCommitNum + '-' + gitShortId
gitCommitId = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
}
}
stage('Apply Templates') {
node {
String currentBranch = sh(
returnStdout: true,
script: "oc get bc tds-pipeline -o='jsonpath={.spec.source.git.ref}'"
).trim()
sh("""
oc apply -f openshift/openshift-template.yml
oc process tds-pipeline BRANCH=${currentBranch} | oc apply -f -
""")
}
}
stage('Build') {
build(
name: 'tds',
buildVersion: buildVersion,
gitCommitId: gitCommitId
)
}
stage('Test') {
test(
name: 'tds',
buildVersion: buildVersion
)
}
stage('Deploy Staging') {
deploy(
name: 'tds',
buildVersion: buildVersion,
environment: 'staging'
)
}
stage('Deploy Prod Trigger') {
inputUrl = env.BUILD_URL ? "(${env.BUILD_URL}deploy-prod-trigger)" : ''
notifyBuild(
message: "Build is ready for Production ${inputUrl}",
color: '#0000FF',
buildVersion: buildVersion
)
timeout(time:1, unit:'DAYS') {
input 'Deploy to Production?'
}
}
stage('Deploy Production') {
deploy(
name: 'tds',
buildVersion: buildVersion,
environment: 'production'
)
}
stage('Publish Trigger') {
inputUrl = env.BUILD_URL ? "(${env.BUILD_URL}publish-trigger)" : '';
notifyBuild(
message: "Build is ready for a Publish ${inputUrl}",
color: '#0000FF',
buildVersion: buildVersion
)
timeout(time:1, unit:'DAYS') {
input 'Publish the npm package?'
}
}
stage('Publish') {
publish(
name: 'tds',
buildVersion: buildVersion
)
}
currentBuild.result = 'SUCCESS'
}
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException flowError) {
currentBuild.result = 'ABORTED'
}
catch (err) {
currentBuild.result = 'FAILURE'
consoleUrl = env.BUILD_URL ? "(${env.BUILD_URL}console)" : '';
notifyBuild(
message: "Build failed ${consoleUrl}",
color: '#FF0000',
buildVersion: buildVersion
)
throw err
}
finally {
if (currentBuild.result == 'SUCCESS') {
notifyBuild(
message: "Build successful",
color: '#00FF00',
buildVersion: buildVersion
)
}
}
def build(Map attrs) {
node {
unstash 'scripts'
ansiColor('xterm') {
sh("./openshift/run-build.sh ${attrs.name} ${attrs.buildVersion} ${attrs.gitCommitId}")
}
}
}
def test(Map attrs) {
node {
unstash 'scripts'
sh("./openshift/run-test.sh ${attrs.name} ${attrs.buildVersion}")
}
}
def deploy(Map attrs) {
node {
unstash 'scripts'
sh("./openshift/run-deploy-docs.sh ${attrs.name} ${attrs.buildVersion} ${attrs.environment}")
}
}
def publish(Map attrs) {
node {
unstash 'scripts'
sh("./openshift/run-publish.sh ${attrs.name} ${attrs.buildVersion}")
}
}
def notifyBuild(Map attrs) {
node {
slackSend(
color: attrs.color,
message: "${env.JOB_NAME} [${attrs.buildVersion}]\n${attrs.message}",
teamDomain: 'telusdigital',
channel: 'tds-bots',
token: env.SLACK_TOKEN
)
}
}