-
Notifications
You must be signed in to change notification settings - Fork 21
/
Jenkinsfile
97 lines (93 loc) · 3.88 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
def runPlaywrightTests(resultDir, browser, grep) {
try {
timeout(120) {
sh """
rm -f results.xml
PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test tests/_sample-test.spec.ts --project $browser --reporter=junit --grep "$grep"|| true
"""
}
} finally {
def summary = junit skipMarkingBuildUnstable: true, skipPublishingChecks: true, testResults: 'results.xml'
return summary
}
}
def withEnvFile(envfile, Closure cb) {
def props = readProperties(file: envfile)
withEnv(props.collect{ entry -> "${entry.key}=${entry.value}" }) {
cb()
}
}
pipeline {
agent { label 'autoconsent-crawler' }
parameters {
string(name: 'TEST_RESULT_ROOT', defaultValue: '/mnt/efs/users/smacbeth/autoconsent/ci', description: 'Where test results and configuration are stored')
choice(name: 'BROWSER', choices: ['chrome', 'webkit', 'iphoneSE', 'firefox'], description: 'Browser')
string(name: 'GREP', defaultValue: '', description: 'filter for tests matching a specific string')
string(name: 'NSITES', defaultValue: '1', description: 'number of sites to test per CMP')
string(name: 'BRANCH', defaultValue: 'main', description: 'Branch or PR to checkout (e.g. pr/123)')
}
environment {
NODENV_VERSION = "16.16.0"
NODENV_ROOT = "/opt/nodeenv"
PATH = "/opt/nodenv/shims:/opt/nodenv/bin:$PATH"
}
stages {
stage('Checkout') {
when {
expression {
// skip the BRANCH variable if this is running in a multibranch job
return env.BRANCH_NAME == null
}
}
steps {
checkout([$class: 'GitSCM', branches: [[name: "${params.BRANCH}"]],
extensions: [[$class: 'LocalBranch']],
userRemoteConfigs: [[refspec: "+refs/pull/*/head:refs/remotes/origin/pr/*", credentialsId: 'GitHubAccess', url: 'https://github.com/duckduckgo/autoconsent.git']]])
}
}
stage('Build') {
steps {
sh '''
npm ci
npx playwright install
'''
script {
if (env.BRANCH_NAME == null) {
currentBuild.description = "${params.BRANCH} - ${params.BROWSER}"
} else {
currentBuild.description = "${env.GIT_COMMIT}"
}
}
}
}
stage('Test') {
steps {
script {
def testsFailed = 0
def testsTotal = 0
withEnv(["NSITES=${params.NSITES}}"]) {
def testEnvs = [
"${params.TEST_RESULT_ROOT}/de.env",
"${params.TEST_RESULT_ROOT}/us.env",
"${params.TEST_RESULT_ROOT}/gb.env"
]
for (testEnv in testEnvs) {
withEnvFile(testEnv) {
def summary = runPlaywrightTests(params.TEST_RESULT_ROOT, params.BROWSER, params.GREP)
testsFailed += summary.failCount
testsTotal += summary.totalCount
}
}
}
githubNotify(
account: 'duckduckgo',
repo: 'autoconsent',
context: 'Tests / Coverage sample',
sha: "${env.GIT_COMMIT}",
description: "${testsFailed}/${testsTotal} failed",
status: testsFailed > 50 ? 'FAILURE' : 'SUCCESS')
}
}
}
}
}