-
Notifications
You must be signed in to change notification settings - Fork 236
/
Jenkinsfile
168 lines (157 loc) · 7.16 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
// For ci.jenkins.io
// https://github.com/jenkins-infra/documentation/blob/master/ci.adoc
properties([
disableConcurrentBuilds(abortPrevious: true),
buildDiscarder(logRotator(numToKeepStr: '5')),
])
if (env.BRANCH_IS_PRIMARY) {
properties([
buildDiscarder(logRotator(numToKeepStr: '10')),
pipelineTriggers([cron('0 18 * * 2')]),
disableConcurrentBuilds(abortPrevious: true),
])
}
def branches = [:]
def splits
def needSplittingFromWorkspace = true
// TODO could use launchable split-subset to split this into bins
for (build = currentBuild.previousCompletedBuild; build != null; build = build.previousCompletedBuild) {
if (build.resultIsBetterOrEqualTo('UNSTABLE')) {
// we have a reference build
echo "not splitting from workspace, reference build should be : ${build.projectName}:${build.number}, with state ${build.result}"
needSplittingFromWorkspace = false
break
}
}
if (needSplittingFromWorkspace) {
node { // When there are no previous build, we need to estimate splits from files which require workspace
checkout scm
splits = splitTests estimateTestsFromFiles: true, parallelism: count(10)
}
} else {
splits = splitTests count(10)
}
def axes = [
jenkinsVersions: ['lts', 'latest'],
platforms: ['linux'],
jdks: [17, 21],
browsers: ['firefox'],
]
stage('Record builds and sessions') {
retry(conditions: [kubernetesAgent(handleNonKubernetes: true), nonresumable()], count: 2) {
node('maven-21') {
infra.checkoutSCM()
def athCommit = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
withCredentials([string(credentialsId: 'launchable-jenkins-acceptance-test-harness', variable: 'LAUNCHABLE_TOKEN')]) {
sh 'launchable verify && launchable record commit'
}
axes['jenkinsVersions'].each { jenkinsVersion ->
infra.withArtifactCachingProxy {
sh "rm -rf target && DISPLAY=:0 ./run.sh firefox ${jenkinsVersion} -Dmaven.repo.local=${WORKSPACE_TMP}/m2repo -B clean process-test-resources"
}
def coreCommit = sh(script: './core-commit.sh', returnStdout: true).trim()
/*
* TODO Add the commits of the transitive closure of the Jenkins WAR under test and the ATH
* JAR to this build.
*/
withCredentials([string(credentialsId: 'launchable-jenkins-acceptance-test-harness', variable: 'LAUNCHABLE_TOKEN')]) {
sh "launchable verify && launchable record build --name ${env.BUILD_TAG}-${jenkinsVersion} --no-commit-collection --commit jenkinsci/acceptance-test-harness=${athCommit} --commit jenkinsci/jenkins=${coreCommit}"
}
}
withCredentials([string(credentialsId: 'launchable-jenkins-acceptance-test-harness', variable: 'LAUNCHABLE_TOKEN')]) {
axes.values().combinations {
def (jenkinsVersion, platform, jdk, browser) = it
def sessionFile = "launchable-session-${jenkinsVersion}-${platform}-jdk${jdk}-${browser}.txt"
sh "launchable record session --build ${env.BUILD_TAG}-${jenkinsVersion} --flavor platform=${platform} --flavor jdk=${jdk} --flavor browser=${browser} >${sessionFile}"
stash name: sessionFile, includes: sessionFile
}
}
}
}
}
branches['CI'] = {
stage('CI') {
retry(count: 2, conditions: [kubernetesAgent(handleNonKubernetes: true), nonresumable()]) {
node('maven-21') {
checkout scm
def mavenOptions = [
'-Dset.changelist',
'-DskipTests',
'-U',
'clean',
'install',
]
infra.runMaven(mavenOptions, 21)
infra.prepareToPublishIncrementals()
}
}
}
}
def skipImageBuild = env.CHANGE_ID && !pullRequest.labels.contains('build-image')
for (int i = 0; i < splits.size(); i++) {
int index = i
axes.values().combinations {
def (jenkinsVersion, platform, jdk, browser) = it
if (jdk == 21 && jenkinsVersion != 'latest') {
return
}
if (jdk != 21 && jenkinsVersion == 'latest') {
return
}
// TODO enable on LTS line when it is based on 2.480 or later
def cspRule = jenkinsVersion == 'latest'
def name = "${jenkinsVersion}-${platform}-jdk${jdk}-${browser}-split${index}"
branches[name] = {
stage(name) {
int retryCounts = 1
retry(count: 2, conditions: [agent(), nonresumable()]) {
String nodeLabel = 'docker-highmem-nonspot'
if (retryCounts == 1) {
// Use a spot instance for the first try
nodeLabel = 'docker-highmem'
}
retryCounts = retryCounts + 1 // increment the retry count before allocating a node in case it fails
node(nodeLabel) {
checkout scm
def image = skipImageBuild ? docker.image('jenkins/ath') : docker.build('jenkins/ath', '--build-arg uid="$(id -u)" --build-arg gid="$(id -g)" ./src/main/resources/ath-container/')
sh 'mkdir -p target/ath-reports && chmod a+rwx target/ath-reports'
def cwd = pwd()
def dockergid = sh label: 'get docker group', returnStdout: true, script: 'getent group docker | cut -d: -f3'
image.inside("--group-add ${dockergid} -v /var/run/docker.sock:/var/run/docker.sock -v '${cwd}/target/ath-reports:/reports:rw' --shm-size 2g") {
def exclusions = splits.get(index).join('\n')
writeFile file: 'excludes.txt', text: exclusions
infra.withArtifactCachingProxy {
realtimeJUnit(
testResults: 'target/surefire-reports/TEST-*.xml',
testDataPublishers: [[$class: 'AttachmentPublisher']],
// Slow test(s) removal can causes a split to get empty which otherwise fails the build.
// The build failure prevents parallel tests executor to realize the tests are gone so same
// split is run to execute and report zero tests - which fails the build. Permit the test
// results to be empty to break the circle: build after removal executes one empty split
// but not letting the build to fail will cause next build not to try those tests again.
allowEmptyResults: true
) {
sh """
set-java.sh ${jdk}
eval \$(vnc.sh)
java -version
run.sh ${browser} ${jenkinsVersion} -Dmaven.repo.local=${WORKSPACE_TMP}/m2repo -Dmaven.test.failure.ignore=true -Dcsp.rule=${cspRule} -DforkCount=1 -B
cp --verbose target/surefire-reports/TEST-*.xml /reports
"""
}
}
}
withCredentials([string(credentialsId: 'launchable-jenkins-acceptance-test-harness', variable: 'LAUNCHABLE_TOKEN')]) {
def sessionFile = "launchable-session-${jenkinsVersion}-${platform}-jdk${jdk}-${browser}.txt"
unstash sessionFile
def session = readFile(sessionFile).trim()
sh "launchable verify && launchable record tests --session ${session} maven './target/ath-reports'"
}
}
}
}
}
}
}
parallel branches
infra.maybePublishIncrementals()