Skip to content

Commit 5f8c5d9

Browse files
committed
[I/Y-Build] Unify definition of test-jobs into one pipeline file
Last part of - #2625
1 parent 0bd5ecb commit 5f8c5d9

File tree

9 files changed

+263
-325
lines changed

9 files changed

+263
-325
lines changed

JenkinsJobs/AutomatedTests/I_unit_tests.groovy

Lines changed: 0 additions & 138 deletions
This file was deleted.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
def TEST_AGENT = null
2+
3+
pipeline {
4+
options {
5+
timeout(time: 600, unit: 'MINUTES')
6+
timestamps()
7+
buildDiscarder(logRotator(numToKeepStr:'15', artifactNumToKeepStr:'5'))
8+
skipDefaultCheckout()
9+
}
10+
parameters {
11+
string(name: 'buildId', trim: true, description: 'Build Id to test. For example: <code>I20251010-0150</code>')
12+
string(name: 'testSuite', defaultValue: 'all', trim: true, description: '''This can be any ant target from
13+
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/blob/master/production/testScripts/configuration/sdk.tests/testScripts/test.xml
14+
''')
15+
string(name: 'testAgent', trim: true, description: '''The Jenkins build agent this test should run on. If not specified to will be read from the
16+
<a href="https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/blob/master/JenkinsJobs/buildConfigurations.json"><code>buildConfigurations.json</code></a>
17+
for the configuration implied by this jobs's name.
18+
''')
19+
}
20+
agent none
21+
stages {
22+
stage('Fetch test configuration') {
23+
when {
24+
beforeAgent true
25+
equals actual: params.testAgent, expected: ''
26+
}
27+
agent {
28+
label 'basic'
29+
}
30+
// Read the eventual test-agent's label, if not provided by the caller (usually it's provided)
31+
steps {
32+
script {
33+
def buildConfigurations = sh(script: "curl --fail https://raw.githubusercontent.com/eclipse-platform/eclipse.platform.releng.aggregator/refs/heads/master/JenkinsJobs/buildConfigurations.json", returnStdout: true)
34+
def testConfiguration = readTestConfiguration(readJSON(text: buildConfigurations))
35+
TEST_AGENT = testConfiguration.agent
36+
echo "Read agent for OS=${testConfiguration.os} ARCH=${testConfiguration.arch}: ${TEST_AGENT}"
37+
}
38+
}
39+
}
40+
stage('Run Tests') {
41+
agent {
42+
label "${ params.testAgent ?: TEST_AGENT }"
43+
}
44+
environment {
45+
// Declaring a jdk and ant the usual way in the 'tools' section, because of unknown reasons, breaks the usage of system commands like xvnc, pkill and sh
46+
ANT_HOME = tool(type:'ant', name:'apache-ant-latest')
47+
ANT_OPTS = "-Djava.io.tmpdir=${pathOf(env.WORKSPACE + '/tmp')}"
48+
}
49+
steps {
50+
// workspace is not always cleaned (a previous clean-up may have failed). Clean before git cloning or custom tools are installed into workspace.
51+
cleanWs()
52+
checkout scmGit(userRemoteConfigs: [[url: "${scm.userRemoteConfigs[0].url}"]], branches: [[name: "${scm.branches[0].name}"]],
53+
extensions: [cloneOption(depth: 1, shallow: true, noTags: true), sparseCheckout([
54+
[path: 'JenkinsJobs/buildConfigurations.json'],
55+
[path: 'JenkinsJobs/shared/utilities.groovy'],
56+
])])
57+
script {
58+
def buildConfigurations = readJSON(file: 'JenkinsJobs/buildConfigurations.json')
59+
def test = readTestConfiguration(buildConfigurations)
60+
env.JAVA_HOME = getJDKInstallationPath(test)
61+
env.PATH = [pathOf("${JAVA_HOME}/bin"), pathOf("${ANT_HOME}/bin"), env.PATH].join(isUnix() ? ':' : ';')
62+
63+
def preambel = ''
64+
if (isUnix()) {
65+
preambel = '''#!/bin/bash -xe
66+
export LANG=en_US.UTF-8
67+
echo " whoami: $(whoami)"
68+
echo " uname -a: $(uname -a)"
69+
70+
# 0002 is often the default for shell users, but it is not when ran from
71+
# a cron job, so we set it explicitly, to be sure of value, so releng group has write access to anything
72+
# we create on shared area.
73+
oldumask=$(umask)
74+
umask 0002
75+
echo "umask explicitly set to 0002, old value was $oldumask"
76+
'''
77+
}
78+
boolean needsXVNC = test.os == 'linux'
79+
// tmp must already exist, for Java to make use of it, in subsequent steps
80+
runScript(needsXVNC, preambel + """
81+
mkdir tmp
82+
83+
echo JAVA_HOME: §[JAVA_HOME]
84+
echo ANT_HOME: §[ANT_HOME]
85+
echo PATH: §[PATH]
86+
java -XshowSettings -version 1>javaSettings.txt 2>&1
87+
88+
curl --fail --output getEBuilder.xml https://download.eclipse.org/eclipse/relengScripts/testScripts/bootstrap/getEBuilder.xml
89+
ant -f getEBuilder.xml -DbuildId=${params.buildId} -Dosgi.os=${test.os} -Dosgi.ws=${test.ws} -Dosgi.arch=${test.arch} -DtestSuite=${params.testSuite}
90+
""")
91+
}
92+
archiveArtifacts '**/eclipse-testing/results/**, *.properties, *.txt'
93+
junit keepLongStdio: true, testResults: '**/eclipse-testing/results/xml/*.xml'
94+
build job: 'Releng/collectTestResults', wait: false, parameters: [
95+
string(name: 'triggeringJob', value: "${JOB_BASE_NAME}"),
96+
string(name: 'buildURL', value: "${BUILD_URL}"),
97+
string(name: 'buildID', value: "${params.buildId}")
98+
]
99+
}
100+
post {
101+
always {
102+
cleanWs()
103+
}
104+
}
105+
}
106+
}
107+
}
108+
109+
@NonCPS
110+
def readTestConfiguration(Map<String, Object> buildConfigurations) {
111+
def matcher = "$JOB_BASE_NAME" =~ /ep(?<major>\d)(?<minor>\d+)(?<type>[A-Z])-unit-(?<os>\w+)-(?<arch>\w+)-java(?<javaVersion>\d+)/
112+
if (!matcher.matches()) {
113+
throw new Exception("Unsupported test job name: $JOB_BASE_NAME" )
114+
}
115+
def buildType = matcher.group('type')
116+
def os = matcher.group('os')
117+
def arch = matcher.group('arch')
118+
def javaVersion = matcher.group('javaVersion').toInteger()
119+
def test = buildConfigurations[buildType].tests.find{ tc -> tc.os == os && tc.arch == arch && tc.javaVersion == javaVersion }
120+
if (test == null) {
121+
// Search again without java version to get at least the agent, but assume a temurin-type JDK (it's most generic)
122+
test = buildConfigurations[buildType].tests.find{ tc -> tc.os == os && tc.arch == arch }
123+
if (test == null) {
124+
throw new Exception("Test configuration not found. OS: ${os}, ARCH: ${arch}")
125+
}
126+
test.javaVersion = javaVersion
127+
test.jdk = [type: 'temurin']
128+
}
129+
return test
130+
}
131+
132+
def runScript(boolean withXVNC, String scriptText) {
133+
if (isUnix()) {
134+
scriptText = scriptText.replaceAll(/§\[(\w+?)\]/,'\\${$1}')
135+
if (withXVNC) {
136+
xvnc(useXauthority: true) {
137+
sh(scriptText)
138+
}
139+
} else {
140+
sh(scriptText)
141+
}
142+
} else {
143+
bat (scriptText.replaceAll(/§\[(\w+?)\]/,'%$1%'))
144+
}
145+
}
146+
147+
def getJDKInstallationPath(Map<String, Object> test) {
148+
def utilities = load 'JenkinsJobs/shared/utilities.groovy'
149+
switch(test.jdk.type) {
150+
case 'tool': return tool(type:'jdk', name: test.jdk.name)
151+
case 'local': return test.jdk.path
152+
case 'install': return utilities.installDownloadableTool('jdk', test.jdk.url)
153+
case 'temurin': return utilities.downloadTemurinJDK(test.javaVersion, test.os, test.arch, test.jdk.ea ? 'ea' : 'ga')
154+
}
155+
}
156+
157+
def pathOf(String path) {
158+
return path.replace('/', isUnix() ? '/' : '\\')
159+
}

JenkinsJobs/Builds/build.jenkinsfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,9 @@ spec:
344344
steps {
345345
script {
346346
for (c in BUILD.tests) {
347-
build job: "${BUILD.testJobFolder}/${TEST_NAME_PREFIX}-${c.os}-${c.arch}-java${c.javaVersion}", wait: false, parameters: [
348-
string(name: 'buildId', value: "${BUILD_IID}")
347+
build job: "${BUILD.testsFolder}/${TEST_NAME_PREFIX}-${c.os}-${c.arch}-java${c.javaVersion}", wait: false, parameters: [
348+
string(name: 'buildId', value: "${BUILD_IID}"),
349+
string(name: 'testAgent', value: "${c.agent}"),
349350
]
350351
}
351352
}

JenkinsJobs/Releng/collectTestResults.jenkinsfile

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pipeline {
2828
extensions: [cloneOption(depth: 1, shallow: true, noTags: true), sparseCheckout([
2929
[path: 'cje-production/'],
3030
[path: 'eclipse.platform.releng.tychoeclipsebuilder/eclipse/publishingFiles/testManifest.xml'],
31+
[path: 'JenkinsJobs/shared/utilities.groovy'],
3132
])])
3233
}
3334
}
@@ -98,20 +99,11 @@ pipeline {
9899
}
99100

100101
def installLatestEclipse(){
101-
def props = null
102-
dir("${WORKSPACE}/git-repo") {
103-
props = readProperties(file: 'cje-production/buildproperties.txt').collectEntries{n, v ->
102+
def props = readProperties(file: "${WORKSPACE}/git-repo/cje-production/buildproperties.txt").collectEntries{n, v ->
104103
v = v.trim();
105104
return [n, (v.startsWith('"') && v.endsWith('"') ? v.substring(1, v.length() - 1) : v)]
106105
}
107-
}
106+
def utilities = load "${WORKSPACE}/git-repo/JenkinsJobs/shared/utilities.groovy"
108107
def eclipseURL = "https://download.eclipse.org/eclipse/downloads/drops4/${props.PREVIOUS_RELEASE_ID}/eclipse-platform-${props.PREVIOUS_RELEASE_VER}-linux-gtk-x86_64.tar.gz"
109-
return install('eclipse', eclipseURL) + '/eclipse --launcher.suppressErrors -nosplash -consolelog'
110-
}
111-
112-
def install(String toolType, String url) {
113-
dir("${WORKSPACE}/tools/${toolType}") {
114-
sh "curl -L ${url} | tar -xzf -"
115-
return "${pwd()}/" + sh(script: 'ls', returnStdout: true).trim()
116-
}
108+
return utilities.installDownloadableTool('eclipse', eclipseURL) + '/eclipse --launcher.suppressErrors -nosplash -consolelog'
117109
}

JenkinsJobs/Releng/deployToMaven.jenkinsfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,6 @@ def determineDeploymentType() {
266266
}
267267

268268
def installLatestCbiAggr(){
269-
return install('cbiAggr', "https://download.eclipse.org/cbi/updates/p2-aggregator/products/nightly/latest/org.eclipse.cbi.p2repo.cli.product-linux.gtk.x86_64.tar.gz") + '/cbiAggr'
270-
}
271-
272-
def install(String toolType, String url) {
273-
dir("${WORKSPACE}/tools/${toolType}") {
274-
sh "curl -L ${url} | tar -xzf -"
275-
return "${pwd()}/" + sh(script: 'ls', returnStdout: true).trim()
276-
}
269+
def utilities = load "${WORKSPACE}/git-repo/JenkinsJobs/shared/utilities.groovy"
270+
return utilities.installDownloadableTool('cbiAggr', "https://download.eclipse.org/cbi/updates/p2-aggregator/products/nightly/latest/org.eclipse.cbi.p2repo.cli.product-linux.gtk.x86_64.tar.gz") + '/cbiAggr'
277271
}

0 commit comments

Comments
 (0)