-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathJenkinsfile-SmokeTest
More file actions
156 lines (138 loc) · 5.29 KB
/
Jenkinsfile-SmokeTest
File metadata and controls
156 lines (138 loc) · 5.29 KB
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
#!groovy
@Library('waluigi@release/7') _
properties([
disableConcurrentBuilds(),
buildDiscarder(logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '1',
daysToKeepStr: '',
numToKeepStr: '50'
)),
parameters([
string(defaultValue: 'next', description: 'The NPM publish tag ', name: 'NPM_TAG', trim: false),
])
])
// Generates a custom route file that contains the next version of Angular to test against
def generateNPMVersionRouteFile(Map args = new LinkedHashMap()) {
writeJSON file: "${args.filePath}", json: args.content
}
// Updates the Angular dependencies to the version specified by the npm tag
def updateDependenciesWithTag(Map args = new LinkedHashMap()) {
String npmTag = args.npmTag ?: 'latest'
sh "yarn add @angular/core@${npmTag} @angular/animations@${npmTag} @angular/common@${npmTag} @angular/compiler@${npmTag} @angular/core@${npmTag} @angular/forms@${npmTag} @angular/platform-browser@${npmTag} @angular-devkit/build-angular@${npmTag} @angular/cli@${npmTag} @angular/compiler-cli@${npmTag}"
}
def runSmokeTests(Map args = new LinkedHashMap()) {
def platforms = args.platforms ?: [
[ browser: "chrome", provider: "lambdatest" ]
]
String routeFilePath = "${WORKSPACE}/customRoutes.json"
String additionalArgs = "--chunk 20 --totalTimeout 1800000 --singleTimeout 90000 --retries 3 --customRoutes ${routeFilePath}"
def processes = [:]
for (int i = 0; i < platforms.size(); i++) {
def platform = platforms.get(i)
def buckets = platform.buckets ?: 1
for (int bucket = 1; bucket <= buckets; bucket++) {
// clousure var - don't inline or jenkins complains
def currBucket = bucket
def suffix = currBucket == 1 ? '' : "-${currBucket}"
// Run using remote provider
if (platform.provider) {
def name = "${platform.browser}-${platform.provider}${suffix}"
processes[name] = {
stage("${name}") {
bedrockRemoteTools.tinyWorkSishTunnel()
bedrockRemoteTools.withRemoteCreds(platform.provider) {
String customArgs = additionalArgs + " --remote ${platform.provider}"
if (platform.provider == "aws") {
customArgs = customArgs + " --sishDomain \"sish.osu.tiny.work\""
}
if (platform.os) {
customArgs = customArgs + " --platformName \"${platform.os}\""
}
generateNPMVersionRouteFile(content: args.routeContent, filePath: routeFilePath)
updateDependenciesWithTag(npmTag: args.npmTag)
bedrockTests(
name: name,
browser: platform.browser,
testDirs: [ "tinymce-angular-component/src/test/ts" ],
bucket: currBucket,
buckets: buckets,
custom: customArgs
)
}
}
}
} else {
// Headless code in case is needed
def name = "headless-${platform.browser}${suffix}"
processes[name] = {
stage("${name}") {
generateNPMVersionRouteFile(content: args.routeContent, filePath: routeFilePath)
updateDependenciesWithTag(npmTag: args.npmTag)
bedrockTests(
name: name,
browser: platform.browser,
testDirs: [ "tinymce-angular-component/src/test/ts" ],
bucket: currBucket,
buckets: buckets,
custom: additionalArgs + " --useSelenium"
)
}
}
}
}
}
parallel processes
}
def notify(Map slackArgs) {
// In shared libraries, the `call` method is not in the pipeline CPS context. We need to call the `steps` object to safely call jenkins steps
steps.retry(3) {
return steps.slackSend([ username: 'TinyMCE Integration Smoke Test', failOnError: true ] + slackArgs)
}
}
timestamps {
tinyPods.node() {
stage('deps') {
yarnInstall()
}
stage('build') {
sh 'yarn build'
}
stage('tests') {
String npmTag = params.NPM_TAG ?: 'latest'
// @angular/core's version is the one baked into the angular app
String nextVersion = sh(script: "npm view @angular/core@${npmTag} version", returnStdout: true).trim()
echo "The upcoming Angular version: ${nextVersion}"
def customRouteContent = readJSON text: """
[{
"request": {
"method": "get",
"path": "/custom/integration/info"
},
"response": {
"status": 200,
"json": {
"version": "${nextVersion}"
}
}
}]
"""
try {
runSmokeTests(npmTag: npmTag, routeContent: customRouteContent)
} catch (Exception e) {
echo "Exception was caught: ${e}"
currentBuild.result = 'FAILURE'
} finally {
if (currentBuild.resultIsWorseOrEqualTo('UNSTABLE')) {
def color = ['UNSTABLE': 'warning', 'FAILURE': 'danger']
def message = currentBuild.result == 'UNSTABLE' ? "Tests failed" : 'An unexpected error occurred while running tests'
notify(
channel: '#tiny-integrations-dev',
color: color.get(currentBuild.result, '#808080'),
message: "${env.JOB_NAME} against ${nextVersion} failed: ${message} (<${env.BUILD_URL}|Open>)"
)
}
}
}
}
}