From 07ef6650a6b28f9820aba2b3c892d6f720df60ba Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Sat, 27 Jul 2019 01:54:24 -0400 Subject: [PATCH] Run the Linux JDK 8 & 11 builds using ACI agents rather than Ubuntu VMs (#4129) * Run the Linux JDK 8 & 11 builds using ACI agents rather than Ubuntu VMs. * A couple of tests failed when run as root. * Since https://github.com/jenkinsci/jnlp-agents/pull/5 is as yet undeployed, install packages ourselves as a workaround. * Revert "Since https://github.com/jenkinsci/jnlp-agents/pull/5 is as yet undeployed, install packages ourselves as a workaround." This reverts commit 2f7e84d67a86e5efbd02305e555f572ca36fd1a4. The changes have been deployed, so the workaround is no longer necessary. --- Jenkinsfile | 19 +++++++++++-------- .../hudson/tasks/ArtifactArchiverTest.java | 6 +++++- ...insBuildsAndWorkspacesDirectoriesTest.java | 10 ++++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 436efd0ed338..c7dc2954de90 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,10 +3,6 @@ /* * This Jenkinsfile is intended to run on https://ci.jenkins.io and may fail anywhere else. * It makes assumptions about plugins being installed, labels mapping to nodes that can build what is needed, etc. - * - * The required labels are "java" and "docker" - "java" would be any node that can run Java builds. It doesn't need - * to have Java installed, but some setups may have nodes that shouldn't have heavier builds running on them, so we - * make this explicit. "docker" would be any node with docker installed. */ // TEST FLAG - to make it easier to turn on/off unit tests for speeding up access to later stuff. @@ -15,7 +11,6 @@ def failFast = false properties([buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '3')), durabilityHint('PERFORMANCE_OPTIMIZED')]) -// see https://github.com/jenkins-infra/documentation/blob/master/ci.adoc for information on what node types are available def buildTypes = ['Linux', 'Windows'] def jdks = [8, 11] @@ -25,7 +20,8 @@ for(j = 0; j < jdks.size(); j++) { def buildType = buildTypes[i] def jdk = jdks[j] builds["${buildType}-jdk${jdk}"] = { - node(buildType.toLowerCase()) { + // see https://github.com/jenkins-infra/documentation/blob/master/ci.adoc#node-labels for information on what node types are available + node(buildType == 'Linux' ? (jdk == 8 ? 'maven' : 'maven-11') : buildType.toLowerCase()) { // First stage is actually checking out the source. Since we're using Multibranch // currently, we can use "checkout scm". stage('Checkout') { @@ -41,7 +37,7 @@ for(j = 0; j < jdks.size(); j++) { // See below for what this method does - we're passing an arbitrary environment // variable to it so that JAVA_OPTS and MAVEN_OPTS are set correctly. withMavenEnv(["JAVA_OPTS=-Xmx1536m -Xms512m", - "MAVEN_OPTS=-Xmx1536m -Xms512m"], jdk) { + "MAVEN_OPTS=-Xmx1536m -Xms512m"], buildType, jdk) { // Actually run Maven! // -Dmaven.repo.local=… tells Maven to create a subdir in the temporary directory for the local Maven repository def mvnCmd = "mvn -Pdebug -U -Dset.changelist help:evaluate -Dexpression=changelist -Doutput=$changelistF clean install ${runTests ? '-Dmaven.test.failure.ignore' : '-DskipTests'} -V -B -Dmaven.repo.local=$m2repo -s settings-azure.xml -e" @@ -107,7 +103,14 @@ infra.maybePublishIncrementals() // This method sets up the Maven and JDK tools, puts them in the environment along // with whatever other arbitrary environment variables we passed in, and runs the // body we passed in within that environment. -void withMavenEnv(List envVars = [], def javaVersion, def body) { +void withMavenEnv(List envVars = [], def buildType, def javaVersion, def body) { + if (buildType == 'Linux') { + // I.e., a Maven container using ACI. No need to install tools. + return withEnv(envVars) { + body.call() + } + } + // The names here are currently hardcoded for my test environment. This needs // to be made more flexible. // Using the "tool" Workflow call automatically installs those tools on the diff --git a/test/src/test/java/hudson/tasks/ArtifactArchiverTest.java b/test/src/test/java/hudson/tasks/ArtifactArchiverTest.java index 5718d732e083..80501f9cb90f 100644 --- a/test/src/test/java/hudson/tasks/ArtifactArchiverTest.java +++ b/test/src/test/java/hudson/tasks/ArtifactArchiverTest.java @@ -54,16 +54,19 @@ import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.*; import static org.junit.Assume.*; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; +import org.jvnet.hudson.test.BuildWatcher; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.TestBuilder; import org.jvnet.hudson.test.recipes.LocalData; public class ArtifactArchiverTest { - + + @ClassRule public static BuildWatcher buildWatcher = new BuildWatcher(); @Rule public JenkinsRule j = new JenkinsRule(); @Test @@ -312,6 +315,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen p.setAssignedNode(slave); FreeStyleBuild build = p.scheduleBuild2(0).get(); + assumeFalse(FILENAME + " should not be readable by " + System.getProperty("user.name"), new File(build.getWorkspace().child(FILENAME).getRemote()).canRead()); j.assertBuildStatus(Result.FAILURE, build); String expectedPath = build.getWorkspace().child(FILENAME).getRemote(); j.assertLogContains("ERROR: Step ‘Archive the artifacts’ failed: java.nio.file.AccessDeniedException: " + expectedPath, build); diff --git a/test/src/test/java/jenkins/model/JenkinsBuildsAndWorkspacesDirectoriesTest.java b/test/src/test/java/jenkins/model/JenkinsBuildsAndWorkspacesDirectoriesTest.java index a89b9a0d84a5..f8bc1802b440 100644 --- a/test/src/test/java/jenkins/model/JenkinsBuildsAndWorkspacesDirectoriesTest.java +++ b/test/src/test/java/jenkins/model/JenkinsBuildsAndWorkspacesDirectoriesTest.java @@ -95,16 +95,18 @@ public void changeWorkspacesDirLog() throws Exception { @Test public void badValueForBuildsDir() { story.then((rule) -> { - final List badValues = Arrays.asList( + final List badValues = new ArrayList<>(Arrays.asList( "blah", "$JENKINS_HOME", "$JENKINS_HOME/builds", "$ITEM_FULL_NAME", "/path/to/builds", "/invalid/$JENKINS_HOME", - "relative/ITEM_FULL_NAME", - "/foo/$ITEM_FULL_NAME", - "/$ITEM_FULLNAME"); + "relative/ITEM_FULL_NAME")); + if (!new File("/").canWrite()) { + badValues.add("/foo/$ITEM_FULL_NAME"); + badValues.add("/$ITEM_FULLNAME"); + } // else perhaps running as root for (String badValue : badValues) { try {