forked from MauroDataMapper/mdm-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
232 lines (220 loc) · 5.43 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
pipeline {
agent any
options {
timestamps()
skipStagesAfterUnstable()
buildDiscarder(logRotator(numToKeepStr: '30'))
}
/*
nvm wrapper has to wrap all steps, interestingly its not supposed to work with the .nvmrc file however if you exclude the version as a blank
string
then it passes the blank string as the version and therefore nvm just does its job and uses the .nvmrc file.
*/
stages {
stage('Tool Versions') {
steps {
nvm('') {
sh 'npm i -g npm@8.3.0'
sh 'node --version'
sh 'npm --version'
}
}
}
stage('Jenkins Clean') {
steps {
sh 'rm -f junit.xml'
sh 'rm -rf test-report'
sh 'rm -rf coverage'
sh 'rm -rf dist'
sh 'rm -f eslint_report.json'
}
}
stage('Install Global') {
steps {
nvm('') {
sh 'npm install -g npm-check'
sh 'npm install -g @angular/cli'
sh 'npm install -g symlinked'
}
}
}
stage('Install Dependencies') {
when {
not {
branch 'main'
}
}
steps {
nvm('') {
sh 'npm ci'
sh 'npm link @maurodatamapper/mdm-resources'
sh 'symlinked names'
}
}
}
stage('Clean Install Dependencies') {
when {
branch 'main'
}
steps {
nvm('') {
sh 'npm ci'
sh 'symlinked names'
}
}
}
stage('License Header Check') {
steps {
warnError('Missing License Headers') {
nvm('') {
sh 'npm run license-check check'
}
}
}
}
stage('Test') {
steps {
nvm('') {
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
sh 'npm run test-with-coverage'
sh 'npm run test-clearCache'
sh "rm -rf /tmp/jest_${JOB_BASE_NAME}"
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: 'test-report/junit.xml'
publishCoverage adapters: [istanbulCoberturaAdapter('coverage/cobertura-coverage.xml')], sourceFileResolver: sourceFiles('NEVER_STORE')
publishHTML([
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : false,
reportDir : 'test-report',
reportFiles : 'index.html',
reportName : 'Test Report',
reportTitles : 'Test'
])
}
}
}
stage('Lint') {
steps {
nvm('') {
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
sh 'npm run eslint-report'
}
}
}
post {
always {
recordIssues qualityGates: [[threshold: 1, type: 'TOTAL_ERROR', unstable: true], [threshold: 1, type: 'TOTAL_HIGH', unstable: true]], tools: [esLint(pattern: '**/eslint_report.xml')]
}
}
}
stage('Distribution Build') {
when{
anyOf{
branch 'develop'
branch 'main'
}
}
steps {
nvm('') {
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
sh 'npm run dist'
sh 'MDM_UI_THEME_NAME=nhs-digital npm run dist'
}
}
}
}
// Deploy develop branch even if tests fail if the code builds, as it'll be an unstable snapshot but we should still deploy
stage('Deploy develop to Artifactory') {
when {
branch 'develop'
}
steps {
rtUpload(
serverId: 'cs-artifactory',
spec: '''{
"files": [
{
"pattern": "dist/mdm-ui-*.tgz",
"target": "artifacts-snapshots/mauroDataMapper/mdm-ui/"
}
]
}''',
)
rtPublishBuildInfo(
serverId: 'cs-artifactory',
)
}
}
stage('Deploy main to Artifactory') {
when {
allOf {
branch 'main'
expression {
currentBuild.currentResult == 'SUCCESS'
}
}
}
steps {
rtUpload(
serverId: 'cs-artifactory',
spec: '''{
"files": [
{
"pattern": "dist/mdm-ui-*.tgz",
"target": "artifacts/mauroDataMapper/mdm-ui/"
}
]
}''',
)
rtPublishBuildInfo(
serverId: 'cs-artifactory',
)
}
}
stage('Sonarqube') {
when {
branch 'develop'
}
steps {
withSonarQubeEnv('JenkinsQube') {
nvm('') {
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
sh 'npm run sonar'
}
}
}
}
}
stage('Continuous Deployment') {
when {
allOf {
branch 'develop'
expression {
currentBuild.currentResult == 'SUCCESS'
}
}
}
steps {
script {
try {
println("Triggering the [continuous-deployment] job")
build quietPeriod: 300, wait: false, job: 'continuous-deployment'
} catch (hudson.AbortException ignored) {
println("Cannot trigger the [continuous-deployment] job as it doesn't exist")
}
}
}
}
}
post {
always {
outputTestResults()
// zulipNotification(topic: 'mdm-ui')
}
}
}