This repository has been archived by the owner on Nov 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
145 lines (106 loc) · 3.3 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
#!groovy
def success = '#78b037'
def fail = '#D54C53'
node {
stage("Source") {
checkout scm
}
stage("Build") {
parallel (
"Initialize virtualenv": {
sh "rm -rf venv"
sh "python3 -m venv venv"
sh "venv/bin/pip install -U wheel pip cffi"
sh "venv/bin/pip install -r requirements.txt"
},
"Build GOV.UK assets": {
ansiColor("xterm") {
sh "./install-govuk-assets"
}
}
)
}
stage("Test") {
parallel (
"Unit tests": {
runTests('unit')
},
"Integration tests": {
runTests('integration')
},
"Functional tests": {
runTests('functional')
}
)
}
if (!BRANCH_NAME.startsWith('PR-')) {
stage("Deploy") {
def branch = "${BRANCH_NAME.replace('_', '-')}"
def appName = cfAppName("ags-gateway", branch)
def url = "https://${appName}.cloudapps.digital"
parallel (
"Deploy to PaaS": {
stash(
name: "app",
includes: ".cfignore,Procfile,app/**,deploy-to-paas,lib/**,*.yml,*.txt,*.pem"
)
node('master') {
unstash "app"
deployToPaaS(appName)
}
if (BRANCH_NAME == 'master') {
slackSend color: success, message: "Deployed ${BRANCH_NAME} branch of Gateway to ${url}"
}
},
"Deploy test client": {
build(
job: 'sue_my_brother/master',
parameters: [
string(name: 'OIDC_CLIENT_ISSUER', value: url),
string(name: 'GATEWAY_BRANCH', value: branch)
]
)
}
)
}
}
}
def cfAppName(appName, branch) {
if (branch != 'master') {
appName = "${appName}-${branch}"
}
return appName
}
def runTests(path) {
ansiColor("xterm") {
try {
sh "venv/bin/pytest --eradicate --flake8 --cov-report xml --cov=app --junitxml=results.xml --pyargs tests/${path}"
} catch(err) {
junit "results.xml"
if (currentBuild.result == 'UNSTABLE') {
currentBuild.result = 'FAILURE'
}
if (BRANCH_NAME == 'master') {
slackSend(color: fail, message: "${path.capitalize()} tests failed on ${BRANCH_NAME} branch of Gateway")
}
throw err
}
junit "results.xml"
}
}
def deployToPaaS(app_name) {
withEnv(["CF_APPNAME=${app_name}"]) {
withCredentials([
usernamePassword(
credentialsId: 'paas-deploy',
usernameVariable: 'CF_USER',
passwordVariable: 'CF_PASSWORD'),
file(
credentialsId: 'environment.sh',
variable: 'ENV_FILE')]) {
ansiColor("xterm") {
sh "./deploy-to-paas"
}
}
}
}