This repository has been archived by the owner on Oct 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile.common.groovy
139 lines (124 loc) · 3.64 KB
/
Jenkinsfile.common.groovy
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
// Load shared devops utils
library identifier: 'devops-library@master', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/BCDevOps/jenkins-pipeline-shared-lib.git'
])
// Edit your app's name below
APP_NAME = 'api'
PROJECT_PREFIX = "jag-shuber"
// You shouldn't have to edit these if you're following the conventions
SLACK_DEV_CHANNEL="#sheriffscheduling_dev"
SLACK_MAIN_CHANNEL="#sheriff_scheduling"
SLACK_PROD_CHANNEL="sheriff_prod_approval"
PATHFINDER_URL = "pathfinder.gov.bc.ca"
class AppEnvironment{
String name
String tag
String url
}
environments = [
dev:new AppEnvironment(name:'Development',tag:'dev',url:'https://dev.jag.gov.bc.ca/sheriff-scheduling/'),
test:new AppEnvironment(name:'Test',tag:'test',url:'https://test.jag.gov.bc.ca/sheriff-scheduling/'),
prod:new AppEnvironment(name:'Prod',tag:'prod',url:'https://dev.jag.gov.bc.ca/sheriff-scheduling/')
]
// Gets the container hash for the latest image in an image stream
def getLatestHash(imageStreamName){
return sh (
script: """oc get istag ${imageStreamName}:latest -o=jsonpath='{@.image.metadata.name}' | sed -e 's/sha256://g'""",
returnStdout: true
).trim()
}
def ensureBuildExists(buildConfigName,templatePath){
if(!openshift.selector( "bc/${buildConfigName}")){
newBuildConfig = sh ( """oc process -f "${env.WORKSPACE}/../workspace@script/${templatePath}" | oc create -f - """)
echo ">> ${newBuildConfig}"
}else{
echo "Build Config '${buildConfigName}' already exists"
}
}
def buildAndVerify(buildConfigName){
echo "Building: ${buildConfigName}"
openshiftBuild bldCfg: buildConfigName, showBuildLogs: 'true', waitTime: '900000'
openshiftVerifyBuild bldCfg: buildConfigName, showBuildLogs: 'true', waitTime: '900000'
}
def tagImage(srcHash, destination, imageStream){
openshiftTag(
destStream: imageStream,
verbose: 'true',
destTag: destination,
srcStream: imageStream,
srcTag: srcHash,
waitTime: '900000'
)
}
def deployAndVerify(srcHash, destination, imageStream){
echo "Deploying ${APP_NAME} to ${destination}"
tagImage(srcHash, destination, imageStream)
// verify deployment
openshiftVerifyDeployment(
deploymentConfig: APP_NAME,
namespace: "${PROJECT_PREFIX}-${destination}",
waitTime: '900000'
)
}
def notifyGood(title,description,buttons=[]){
if(env.SLACK_HOOK){
slackNotify(
title,
description,
'good',
env.SLACK_HOOK,
SLACK_MAIN_CHANNEL,
buttons
)
}else{
echo "Would notify goodness via slack";
}
}
def notifyNewDeployment(environment,url,nextButtonText){
notifyGood(
"New ${APP_NAME} in ${environment} 🚀",
"Changes: ${getChangeString()}",
[
[
type: "button",
text: "View New Version",
url: "${url}"
],
[
type: "button",
text: nextButtonText,
style: "primary",
url: "${currentBuild.absoluteUrl}/input"
]
]
)
}
def notifyError(title,description){
if(env.SLACK_HOOK){
slackNotify(
title,
description,
'danger',
env.SLACK_HOOK,
SLACK_DEV_CHANNEL,
[
[
type: "button",
text: "View Build Logs",
style:"danger",
url: "${currentBuild.absoluteUrl}/console"
]
]
)
}else{
echo "Would notify error via slack";
}
}
def notifyDeploymentError(environment,error){
notifyError(
"Couldn't deploy ${APP_NAME} to ${environment} 🤕",
"The latest deployment of the ${APP_NAME} to ${environment} seems to have failed\n'${error.message}'"
)
}
return this