-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
127 lines (117 loc) · 4.55 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
@Library('aboe026') _ // groovylint-disable-line VariableName, UnusedVariable
import org.aboe026.ShieldsIoBadges
node {
def packageJson
def workDir = "${WORKSPACE}/${env.BRANCH_NAME}-${env.BUILD_ID}"
def nodeImage = 'node:18'
def version
def exceptionThrown = false
def badges = new ShieldsIoBadges(this, 'shields.io-badge-results')
def uploadBadges = env.BRANCH_NAME == 'main'
try {
ansiColor('xterm') {
dir(workDir) {
stage('Pull Runtime Image') {
sh "docker pull ${nodeImage}"
}
docker.image(nodeImage).inside {
parallel(
'env': {
stage('Runtime Versions') {
sh 'node --version'
sh 'npm --version'
}
},
'proj': {
stage('Checkout') {
checkout scm
}
stage('Install') {
sh 'npm ci'
}
}
)
stage('Set Build Number') {
packageJson = readJSON file: 'package.json'
version = "${packageJson.version}+${env.BUILD_ID}"
currentBuild.displayName = version
}
stage('Lint') {
sh 'npm run lint'
}
stage('Validate Results') {
sh 'npm run validate:results'
}
stage('Unit Tests') {
try {
sh 'npm run test:unit:xml'
} catch (err) {
exceptionThrown = true
println 'Exception was caught in try block of unit tests stage.'
println err
} finally {
junit testResults: 'test-results/unit.xml', allowEmptyResults: true
recordCoverage(
skipPublishingChecks: true,
sourceCodeRetention: 'EVERY_BUILD',
tools: [
[
parser: 'COBERTURA',
pattern: 'coverage/unit/cobertura-coverage.xml'
]
]
)
if (uploadBadges) {
badges.uploadCoverageResult(
branch: env.BRANCH_NAME
)
}
}
}
stage('E2E Tests') {
try {
sh 'npm run test:e2e:xml'
} catch (err) {
exceptionThrown = true
println 'Exception was caught in try block of e2e tests stage.'
println err
} finally {
junit testResults: 'test-results/e2e.xml', allowEmptyResults: true
def e2eDebugLogs = 'test/e2e/.temp-work-dir/e2e-debug.txt'
if (fileExists(e2eDebugLogs)) {
archiveArtifacts artifacts: e2eDebugLogs
}
}
}
}
}
}
} catch (err) {
exceptionThrown = true
println 'Exception was caught in try block of jenkins job.'
println err
} finally {
if (uploadBadges) {
badges.uploadBuildResult(
branch: env.BRANCH_NAME
)
}
stage('Cleanup') {
try {
sh "rm -rf ${workDir}"
} catch (err) {
println 'Exception deleting working directory'
println err
}
try {
sh "rm -rf ${workDir}@tmp"
} catch (err) {
println 'Exception deleting temporary working directory'
println err
}
if (exceptionThrown) {
error('Exception was thrown earlier')
}
}
}
}