Skip to content

Commit

Permalink
Fix Acceptance tests (#504)
Browse files Browse the repository at this point in the history
* Try acceptance tests with a newer base version for the plugin

* Fix xpath for button selection and change test to integration

* Update test harness version

* Update JDK requirement

* Update codenarc

* Update toolchain for acceptance tests

* Remove unnecessary jenkins version filtering

* Set JAVA_HOME to run Jenkins itself

* Revert back the test harness version

* Remove toolchain for acceptance test

* Update gradle version in tests

* Reset default version of gradle in old tests

* Update gradle tool setup

* Remove Gradle 5.x from certain testing scenarios

* Update default version for acceptance tests

* Remove toolchain setup in acceptance tests

* Bring back toolchain setup for compilation
  • Loading branch information
welandaz authored Nov 22, 2024
1 parent b8e22a2 commit 5d7152a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 36 deletions.
32 changes: 10 additions & 22 deletions acceptance-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ plugins {
val ciJenkinsBuild: Boolean by (gradle as ExtensionAware).extra

java {
// Only used for compilation. We don't rely on toolchain for running the tests,
// as Jenkins ATH doesn't allow to specify the JAVA_HOME.
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
Expand Down Expand Up @@ -40,18 +42,13 @@ dependencies {
add(gradlePlugin.name, project(path = ":", configuration = "gradlePluginJpi"))
}

val currentJava = JavaVersion.current()

val jenkinsVersions = listOf(
JenkinsVersion.LATEST,
JenkinsVersion.LATEST_LTS,
JenkinsVersion.V2_401
JenkinsVersion.V2_440
)

jenkinsVersions
.filter { jenkinsVersion ->
jenkinsVersion.isDefault || currentJava.isCompatibleWith(jenkinsVersion.requiredJavaVersion)
}
.forEach { jenkinsVersion ->
val downloadJenkinsTask =
tasks.register<Download>("downloadJenkins${jenkinsVersion.label}") {
Expand Down Expand Up @@ -85,10 +82,6 @@ jenkinsVersions
!ciJenkinsBuild && !OperatingSystem.current().isWindows
}

javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(jenkinsVersion.javaVersion)
})

systemProperties(
mapOf(
"jdk.xml.xpathExprOpLimit" to 150
Expand All @@ -107,26 +100,23 @@ jenkinsVersions
}
}

data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVersion: JavaLanguageVersion) {
data class JenkinsVersion(val version: String, val downloadUrl: URL) {

companion object {

private const val LATEST_VERSION = "latest"
private const val LATEST_LTS_VERSION = "latest-lts"
private const val V2_401_VERSION = "2.401.3"
private const val V2_440_VERSION = "2.440.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, JAVA_17)
val LATEST = of(LATEST_VERSION)
val LATEST_LTS = of(LATEST_LTS_VERSION)
val V2_401 = of(V2_401_VERSION)
val V2_440 = of(V2_440_VERSION)

private fun of(version: String, javaVersion: JavaLanguageVersion = JAVA_11): JenkinsVersion {
private fun of(version: String): JenkinsVersion {
val downloadUrl =
when (version) {
LATEST_VERSION -> "${MIRROR}/current/latest/jenkins.war"
Expand All @@ -139,14 +129,14 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer
}
}

return JenkinsVersion(version, URL(downloadUrl), javaVersion)
return JenkinsVersion(version, URL(downloadUrl))
}

private fun isJenkinsVersion(version: String) = JENKINS_VERSION_PATTERN.matches(version)
}

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

val label: String
get() = if (isJenkinsVersion(version)) {
Expand All @@ -155,6 +145,4 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer
version.split("-").joinToString(separator = "") { it.capitalized() }
}

val requiredJavaVersion: JavaVersion
get() = JavaVersion.toVersion(javaVersion.toString())
}
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ plugins {
group = "org.jenkins-ci.plugins"
description = "This plugin adds Gradle support to Jenkins"

val coreBaseVersion = "2.401"
val coreBaseVersion = "2.440"
val corePatchVersion = "3"
val coreBomVersion = "2745.vc7b_fe4c876fa_"
val coreBomVersion = "3387.v0f2773fa_3200"

val gradleExt = (gradle as ExtensionAware).extra

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ class BuildScanIntegrationTest extends BaseGradleIntegrationTest {

def 'detects build scan in pipeline log'() {
given:
gradleInstallationRule.gradleVersion = '7.3.3'
gradleInstallationRule.addInstallation()
def pipelineJob = j.createProject(WorkflowJob)
pipelineJob.setDefinition(new CpsFlowDefinition("""
node {
stage('Build') {
// Run the maven build
def gradleHome = tool name: '5.5', type: 'gradle'
def gradleHome = tool name: '${gradleInstallationRule.gradleVersion}', type: 'gradle'
writeFile file: 'settings.gradle', text: ''
writeFile file: 'build.gradle', text: "buildScan { termsOfServiceUrl = 'https://gradle.com/terms-of-service'; termsOfServiceAgree = 'yes' }"
if (isUnix()) {
Expand Down Expand Up @@ -125,7 +126,7 @@ node {

def 'detects build scan in pipeline log using withGradle'() {
given:
gradleInstallationRule.gradleVersion = '5.6.4'
gradleInstallationRule.gradleVersion = '7.3.3'
gradleInstallationRule.addInstallation()
def pipelineJob = j.createProject(WorkflowJob)
pipelineJob.setDefinition(new CpsFlowDefinition("""
Expand Down Expand Up @@ -174,7 +175,7 @@ node {

def 'does not find build scans in pipeline logs when none have been published'() {
given:
gradleInstallationRule.gradleVersion = '5.6.4'
gradleInstallationRule.gradleVersion = '7.3.3'
gradleInstallationRule.addInstallation()
def pipelineJob = j.createProject(WorkflowJob)
pipelineJob.setDefinition(new CpsFlowDefinition("""
Expand Down Expand Up @@ -206,7 +207,7 @@ node {

def 'does not find build scans in pipeline logs when none have been published with withGradle'() {
given:
gradleInstallationRule.gradleVersion = '5.6.4'
gradleInstallationRule.gradleVersion = '7.3.3'
gradleInstallationRule.addInstallation()
def pipelineJob = j.createProject(WorkflowJob)
pipelineJob.setDefinition(new CpsFlowDefinition("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BuildScanInjectionGradleIntegrationTest extends BaseGradleIntegrationTest

private static final String MSG_INIT_SCRIPT_APPLIED = "Connection to Develocity: http://foo.com"

private static final List<String> GRADLE_VERSIONS = ['4.10.3', '5.6.4', '6.9.4', '7.6.4', '8.9']
private static final List<String> GRADLE_VERSIONS = ['4.10.3', '6.9.4', '7.6.4', '8.9']

private static final EnvVars EMPTY_ENV = new EnvVars()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package hudson.plugins.gradle.injection

import hudson.console.ConsoleNote
import hudson.model.Actionable
import hudson.plugins.gradle.BaseJenkinsIntegrationTest
import hudson.plugins.gradle.BuildScanAction
import spock.lang.Specification
import spock.lang.Subject

import java.nio.charset.StandardCharsets

class DevelocityExceptionLogProcessorTest extends Specification {
class DevelocityExceptionLogProcessorTest extends BaseJenkinsIntegrationTest {

private static final String GRADLE_PLUGIN_ERROR = "Internal error in Gradle Enterprise Gradle plugin: com.acme.FooBar"
private static final String MAVEN_EXTENSION_ERROR = "[ERROR] Internal error in Gradle Enterprise Maven extension: com.acme.FooBar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ class InjectionConfigTest extends BaseJenkinsIntegrationTest {
}

private static HtmlButton getAddButton(HtmlForm form, String label) {
def xpath = "//div[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')]//button[contains(@class, 'repeatable-add')]"

return form.getFirstByXPath(xpath)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MavenExtensionsDetectorTest extends Specification {
dir {
'.mvn' {
'extensions.xml'(generateExtensionsXml(
*(extensions.collect({ MavenCoordinates.parseCoordinates(it) }))))
*(extensions.collect { MavenCoordinates.parseCoordinates(it) })))
}
}

Expand Down Expand Up @@ -68,9 +68,9 @@ class MavenExtensionsDetectorTest extends Specification {
dir {
'.mvn' {
'extensions.xml'(
generateExtensionsXml(
MavenCoordinates.parseCoordinates('my:ext:1.0'),
MavenCoordinates.parseCoordinates('my:ext-ccud:1.0')))
generateExtensionsXml(
MavenCoordinates.parseCoordinates('my:ext:1.0'),
MavenCoordinates.parseCoordinates('my:ext-ccud:1.0')))
}
}

Expand Down

0 comments on commit 5d7152a

Please sign in to comment.