|
| 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 | +} |
0 commit comments