Skip to content

Commit

Permalink
Update Jenkins min version and adapt build (#461)
Browse files Browse the repository at this point in the history
* Update Jenkins versions and adapt JDK requirement

Latest Jenkins requires Java 17 or above.
Recently added plugin dependencies (jackson) require Jenkins 2.401.3
Jenkins 2.401.3 requires Java 11 or above.
Animal Sniffer is not needed with Java 11, replaced by compileJava `options.release = 11`.

* Remove `autoInjectionSkippedWhenOldMavenPlugin` test as it requires maven-plugin 3.14 which won't install on the current Jenkins version

* Try to kill Gradle daemons on Windows

* Try again to kill Gradle daemons on Windows

* Ignore CodeNarc warn
  • Loading branch information
alextu authored Jun 25, 2024
1 parent a52630a commit 6d5108d
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 55 deletions.
11 changes: 6 additions & 5 deletions acceptance-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ val currentJava = JavaVersion.current()
val jenkinsVersions = listOf(
JenkinsVersion.LATEST,
JenkinsVersion.LATEST_LTS,
JenkinsVersion.V2_375
JenkinsVersion.V2_401
)

jenkinsVersions
Expand Down Expand Up @@ -113,17 +113,18 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer

private const val LATEST_VERSION = "latest"
private const val LATEST_LTS_VERSION = "latest-lts"
private const val V2_388_VERSION = "2.388"
private const val V2_401_VERSION = "2.401.3"

private const val MIRROR = "https://updates.jenkins.io"

private val JENKINS_VERSION_PATTERN = "^\\d+([.]\\d+)*?\$".toRegex()

private val JAVA_11 = JavaLanguageVersion.of(11)
private val JAVA_17 = JavaLanguageVersion.of(17)

val LATEST = of(LATEST_VERSION)
val LATEST = of(LATEST_VERSION, JAVA_17)
val LATEST_LTS = of(LATEST_LTS_VERSION)
val V2_375 = of(V2_388_VERSION)
val V2_401 = of(V2_401_VERSION)

private fun of(version: String, javaVersion: JavaLanguageVersion = JAVA_11): JenkinsVersion {
val downloadUrl =
Expand All @@ -145,7 +146,7 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer
}

val isDefault: Boolean
get() = version == V2_388_VERSION
get() = version == V2_401_VERSION

val label: String
get() = if (isJenkinsVersion(version)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package hudson.plugins.gradle;

import com.google.common.collect.ImmutableMap;
import hudson.plugin.gradle.ath.updatecenter.WithVersionOverrides;
import org.apache.commons.text.StringSubstitutor;
import org.jenkinsci.test.acceptance.junit.WithOS;
import org.jenkinsci.test.acceptance.junit.WithPlugins;
Expand Down Expand Up @@ -54,28 +53,6 @@ public void mavenJobSendsBuildScan() {
assertBuildScanPublished(build);
}

@Test
@WithVersionOverrides("maven-plugin=3.14")
@WithPlugins("maven-plugin")
@Ignore("https://github.com/gradle/dv/issues/35892")
public void autoInjectionSkippedWhenOldMavenPlugin() {
// given
MavenModuleSet job = jenkins.jobs.create(MavenModuleSet.class);

job.configure();
job.copyDir(resource("/simple_maven_project"));
job.goals.set("clean compile");

job.save();

// when
Build build = job.startBuild();

// then
build.shouldSucceed();
assertBuildScanNotPublished(build);
}

@Test
public void freestyleJobSendsBuildScan() {
// given
Expand Down
31 changes: 15 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import java.util.zip.ZipFile

plugins {
id("org.jenkins-ci.jpi") version "0.50.0"
id("ru.vyarus.animalsniffer") version "1.7.1"
id("com.github.spotbugs") version "6.0.15"
id("codenarc")
id("buildlogic.reproducible-archives")
Expand All @@ -17,9 +16,9 @@ plugins {
group = "org.jenkins-ci.plugins"
description = "This plugin adds Gradle support to Jenkins"

val coreBaseVersion = "2.303"
val coreBaseVersion = "2.401"
val corePatchVersion = "3"
val coreBomVersion = "1500.ve4d05cd32975"
val coreBomVersion = "2745.vc7b_fe4c876fa_"

val gradleExt = (gradle as ExtensionAware).extra

Expand Down Expand Up @@ -71,14 +70,18 @@ jenkinsPlugin {

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
languageVersion.set(JavaLanguageVersion.of(11))
}

registerFeature("optionalPlugin") {
usingSourceSet(sourceSets["main"])
}
}

tasks.compileJava {
options.release = 11
}

// see https://github.com/jenkinsci/gradle-jpi-plugin#customizing-further
tasks.server.configure {
execSpec {
Expand All @@ -102,8 +105,10 @@ dependencies {
implementation("org.jenkins-ci.plugins.workflow:workflow-step-api")
implementation("io.jenkins.plugins:okhttp-api")

"optionalPluginImplementation"("org.jenkins-ci.main:maven-plugin:3.14") {
"optionalPluginImplementation"("org.jenkins-ci.main:maven-plugin:3.23") {
because("Lowest version that works with our dependencies")
// conflicts with Jenkins bom bringing Guice 6.0.0
exclude(group = "com.google.inject", module = "guice")
}

// Higher versions fail in our tests with ClassNotFoundException during SCM initialization unless Jenkins is updated
Expand All @@ -120,9 +125,7 @@ dependencies {
add(includedLibs.name, "com.gradle:common-custom-user-data-maven-extension:${commonCustomUserDataMavenExtensionVersion}")
add(includedLibs.name, project(path = ":configuration-maven-extension", configuration = "mvnExtension"))

signature("org.codehaus.mojo.signature:java18:1.0@signature")

testImplementation("org.jenkins-ci.main:jenkins-test-harness")
testImplementation("org.jenkins-ci.main:jenkins-test-harness:2225.v04fa_3929c9b_5")
testImplementation("org.jenkins-ci.main:jenkins-test-harness-tools:2.2")
testImplementation("io.jenkins:configuration-as-code:1.4")
testImplementation("org.jenkins-ci.plugins:timestamper")
Expand Down Expand Up @@ -175,13 +178,6 @@ tasks.spotbugsTest {

val main: SourceSet by sourceSets.getting

animalsniffer {
toolVersion = "1.18"
sourceSets = listOf(main)
// We need to exclude this dependency from animalsniffer since it contains an invalid class
excludeJars = listOf("icu4j-*")
}

val test: SourceSet by sourceSets.getting

codenarc {
Expand All @@ -193,7 +189,10 @@ tasks.test {
systemProperties(
mapOf(
"hudson.model.DownloadService.noSignatureCheck" to true,
"jenkins.test.timeout" to 300 // override default timeout
"jenkins.test.timeout" to 300, // override default timeout
"jdk8.home" to javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(8)
}.get().metadata.installationPath.toString()
)
)
ignoreFailures = ciJenkinsBuild
Expand Down
4 changes: 0 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ include("configuration-maven-extension")

rootProject.name = "gradle-plugin"

if (!JavaVersion.current().isJava11) {
throw GradleException("Build requires Java 11")
}

val gradleExt = (gradle as ExtensionAware).extra

val ciJenkinsBuild by gradleExt { System.getenv("JENKINS_URL") != null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package hudson.plugins.gradle
import com.cloudbees.plugins.credentials.CredentialsProvider
import com.cloudbees.plugins.credentials.CredentialsScope
import com.cloudbees.plugins.credentials.domains.Domain
import hudson.Functions
import hudson.slaves.DumbSlave
import hudson.util.Secret
import org.jenkinsci.plugins.plaincredentials.StringCredentials
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl
import org.junit.Rule
import org.junit.rules.RuleChain

import java.util.concurrent.TimeUnit

/**
* Base class for tests that need a Jenkins instance and Gradle tool.
*/
Expand Down Expand Up @@ -64,4 +67,20 @@ abstract class BaseGradleIntegrationTest extends AbstractIntegrationTest {
CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), creds)
}

@SuppressWarnings("CatchException")
def cleanup() {
if(Functions.isWindows()) {
try {
println 'Killing Gradle processes'
def proc = '''WMIC PROCESS where "Name like 'java%%' AND CommandLine like '%%GradleDaemon%%'" Call Terminate"'''.execute()
proc.waitFor(30, TimeUnit.SECONDS)
println "output: ${proc.text}"
println "code: ${proc.exitValue()}"
} catch (Exception e) {
System.err.println('Failed killing Gradle daemons')
e.printStackTrace()
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hudson.plugins.gradle

import hudson.model.FreeStyleProject
import hudson.model.JDK
import hudson.plugins.gradle.injection.MavenSnippets
import hudson.plugins.timestamper.TimestamperBuildWrapper
import hudson.tasks.BatchFile
Expand All @@ -13,16 +14,23 @@ import org.jvnet.hudson.test.CreateFileBuilder
import org.jvnet.hudson.test.ExtractResourceSCM
import org.jvnet.hudson.test.JenkinsRule
import org.jvnet.hudson.test.ToolInstallations
import spock.lang.Requires
import spock.lang.Unroll

import java.nio.file.Files
import java.nio.file.Paths

@Unroll
@SuppressWarnings("GStringExpressionWithinString")
class BuildScanIntegrationTest extends BaseGradleIntegrationTest {
private static final String JDK8_SYS_PROP = 'jdk8.home'

@Requires(value = { hasJdk8() }, reason = "Gradle 3 and 4 require Java 8")
def 'build scans for plugin version #buildScanVersion is discovered'() {
given:
gradleInstallationRule.gradleVersion = gradleVersion
gradleInstallationRule.addInstallation()
setJdk8()
FreeStyleProject p = j.createFreeStyleProject()
p.buildersList.add(buildScriptBuilder(buildScanVersion))
p.buildersList.add(new Gradle(tasks: 'hello', gradleName: gradleVersion, switches: "${args} --no-daemon"))
Expand Down Expand Up @@ -251,15 +259,16 @@ stage('Final') {
new URL(action.scanUrls.get(0))
}

@Requires(value = { hasJdk8() }, reason = "Gradle 3 and 4 require Java 8")
def 'build scan action is exposed via rest API'() {
given:
gradleInstallationRule.gradleVersion = '3.4'
gradleInstallationRule.addInstallation()
setJdk8()
FreeStyleProject p = j.createFreeStyleProject()
p.buildersList.add(buildScriptBuilder('1.8'))
p.buildersList.add(new Gradle(tasks: 'hello', gradleName: '3.4', switches: '-Dscan --no-daemon'))


when:
def build = j.buildAndAssertSuccess(p)

Expand Down Expand Up @@ -305,4 +314,14 @@ tasks.register("hello") { doLast { println("Hello") } }''')
private static CreateFileBuilder settingsScriptBuilder(String gePluginVersion) {
return new CreateFileBuilder('settings.gradle', "plugins { id 'com.gradle.enterprise' version '${gePluginVersion}' }")
}

private setJdk8() {
j.jenkins.setJDKs(Collections.singleton(new JDK('JDK8', System.getProperty(JDK8_SYS_PROP))))
}

private static hasJdk8() {
def jdk8SysProp = System.getProperty(JDK8_SYS_PROP)
return jdk8SysProp && Files.exists(Paths.get(jdk8SysProp))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@

package hudson.plugins.gradle

import com.gargoylesoftware.htmlunit.html.HtmlButton
import com.gargoylesoftware.htmlunit.html.HtmlForm
import com.gargoylesoftware.htmlunit.html.HtmlPage
import com.google.common.base.Joiner
import hudson.EnvVars
import hudson.model.FreeStyleBuild
import hudson.model.FreeStyleProject
import hudson.model.Result
import hudson.tools.InstallSourceProperty
import hudson.util.VersionNumber
import org.htmlunit.html.HtmlButton
import org.htmlunit.html.HtmlForm
import org.htmlunit.html.HtmlPage
import org.jvnet.hudson.test.CreateFileBuilder
import org.jvnet.hudson.test.JenkinsRule.WebClient
import spock.lang.Unroll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class BuildScanInjectionGradleIntegrationTest extends BaseGradleIntegrationTest
sh "'\${gradleHome}/bin/gradle' help --no-daemon --console=plain"
} else {
bat(/"\${gradleHome}\\bin\\gradle.bat" help --no-daemon --console=plain/)
bat(/"\${gradleHome}\\bin\\gradle.bat" --stop/)
}
}
}
Expand Down Expand Up @@ -859,6 +860,7 @@ class BuildScanInjectionGradleIntegrationTest extends BaseGradleIntegrationTest
sh "'\${gradleHome}/bin/gradle' help --no-daemon --console=plain"
} else {
bat(/"\${gradleHome}\\bin\\gradle.bat" help --no-daemon --console=plain/)
bat(/"\${gradleHome}\\bin\\gradle.bat" --stop/)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package hudson.plugins.gradle.injection

import com.gargoylesoftware.htmlunit.html.HtmlButton
import com.gargoylesoftware.htmlunit.html.HtmlForm
import hudson.plugins.gradle.BaseJenkinsIntegrationTest
import hudson.slaves.EnvironmentVariablesNodeProperty
import hudson.util.FormValidation
import hudson.util.XStream2
import org.htmlunit.html.HtmlButton
import org.htmlunit.html.HtmlForm
import spock.lang.Shared
import spock.lang.Subject
import spock.lang.Unroll
Expand Down Expand Up @@ -311,7 +311,7 @@ class InjectionConfigTest extends BaseJenkinsIntegrationTest {
}

private static HtmlButton getAddButton(HtmlForm form, String label) {
def xpath = "//div[contains(@class, 'setting-name') and text() = '$label']/following-sibling::div[contains(@class, 'setting-main')]//span[contains(@class, 'repeatable-add')]//button[text() = 'Add']"
def xpath = "//div[text() = '$label']/following-sibling::div[contains(@class, 'setting-main')]//span[contains(@class, 'repeatable-add')]//button[text() = 'Add']"
return form.getFirstByXPath(xpath)
}
}

0 comments on commit 6d5108d

Please sign in to comment.