From 95d97ff75ae6ff90fdf189632eaac4f81d6ff492 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Thu, 15 Aug 2019 10:12:17 +0200 Subject: [PATCH 1/9] Introduce new buildPluginWithGradle() step and deprecate Gradle Support in buildPlugin() --- README.adoc | 5 +- vars/buildPlugin.groovy | 1 + vars/buildPluginWithGradle.groovy | 86 +++++++++++++++++++++++++++++++ vars/buildPluginWithGradle.txt | 19 +++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 vars/buildPluginWithGradle.groovy create mode 100644 vars/buildPluginWithGradle.txt diff --git a/README.adoc b/README.adoc index 271e28caf..4313350ef 100644 --- a/README.adoc +++ b/README.adoc @@ -9,7 +9,10 @@ Check link:https://github.com/jenkins-infra/documentation/blob/master/ci.adoc[th === buildPlugin -Applies the appropriate defaults for building a Maven- or Gradle-based plugin project on +| WARNING: Gradle support in `buildPlugin()` is deprecated and will be eventually removed. Please use `buildPluginWithGradle()` | +| --- | + +Applies the appropriate defaults for building a Maven-based plugin project on Linux and Windows. You are advised to be using a link:https://github.com/jenkinsci/plugin-pom/blob/master/README.md[2.x parent POM]. diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index c812a9a7d..7eed5ee3a 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -101,6 +101,7 @@ def call(Map params = [:]) { } infra.runMaven(mavenOptions, jdk, null, null, addToolEnv) } else { + echo "WARNING: Gradle mode for buildPlugin() is deprecated, please use buildPluginWithGradle()" List gradleOptions = [ '--no-daemon', 'cleanTest', diff --git a/vars/buildPluginWithGradle.groovy b/vars/buildPluginWithGradle.groovy new file mode 100644 index 000000000..34ad53ef5 --- /dev/null +++ b/vars/buildPluginWithGradle.groovy @@ -0,0 +1,86 @@ +#!/usr/bin/env groovy + +/** + * Simple wrapper step for building a plugin with Gradle. + */ +def call(Map params = [:]) { + // Faster build and reduces IO needs + properties([ + durabilityHint('PERFORMANCE_OPTIMIZED'), + buildDiscarder(logRotator(numToKeepStr: '5')), + ]) + + def repo = params.containsKey('repo') ? params.repo : null + def failFast = params.containsKey('failFast') ? params.failFast : true + def timeoutValue = params.containsKey('timeout') ? params.timeout : 60 + if(timeoutValue > 180) { + echo "Timeout value requested was $timeoutValue, lowering to 180 to avoid Jenkins project's resource abusive consumption" + timeoutValue = 180 + } + + boolean publishingIncrementals = false + boolean archivedArtifacts = false + Map tasks = [failFast: failFast] + buildPlugin.getConfigurations(params, true).each { config -> + String label = config.platform + String jdk = config.jdk + String jenkinsVersion = config.jenkins + String javaLevel = config.javaLevel + + String stageIdentifier = "${label}-${jdk}${jenkinsVersion ? '-' + jenkinsVersion : ''}" + + tasks[stageIdentifier] = { + node(label) { + timeout(timeoutValue) { + // Archive artifacts once with pom declared baseline + boolean doArchiveArtifacts = !jenkinsVersion && !archivedArtifacts + if (doArchiveArtifacts) { + archivedArtifacts = true + } + + stage("Checkout (${stageIdentifier})") { + infra.checkout(repo) + } + + stage("Build (${stageIdentifier})") { + if (javaLevel != null) { + echo "WARNING: java.level is not supported in the buildGradlePlugin(). This parmeter will be ignored" + } + //TODO(oleg-nenashev): Once supported by Gradle JPI Plugin, pass jenkinsVersion + if (jenkinsVersion != null) { + echo "WARNING: Jenkins version is not supported in buildGradlePlugin(). This parmeter will be ignored" + } + List gradleOptions = [ + '--no-daemon', + 'cleanTest', + 'build', + ] + String command = "gradlew ${gradleOptions.join(' ')}" + if (isUnix()) { + command = "./" + command + } + infra.runWithJava(command, jdk) + } + + stage("Archive (${stageIdentifier})") { + junit testReports '**/build/test-results/**/*.xml' + + //TODO(oleg-nenashev): Add static analysis results publishing like in buildPlugin() for Maven + + // TODO do this in a finally-block so we capture all test results even if one branch aborts early + if (failFast && currentBuild.result == 'UNSTABLE') { + error 'There were test failures; halting early' + } + if (doArchiveArtifacts) { + archiveArtifacts artifacts: '**/build/libs/*.hpi,**/build/libs/*.jpi', fingerprint: true + } + } + } + } + } + } + + timestamps { + parallel(tasks) + } +} diff --git a/vars/buildPluginWithGradle.txt b/vars/buildPluginWithGradle.txt new file mode 100644 index 000000000..e06e108c1 --- /dev/null +++ b/vars/buildPluginWithGradle.txt @@ -0,0 +1,19 @@ +

+ Builds a Jenkins plugin using Gradle. +

+

+ The implementation follows the standard build/test/archive pattern. + Note that the Gradle flow for Jenkins plugins offers less functionality than the Maven flow, + some key features are not supported: Incrementals - JEP-305, standard static analysis flows, etc. + The current version also does not allow configuring the jenkinsVersion. +

+ +

+ Usage. The method can be used in the same way as buildPlugin() for Maven projects. + See the documentation in the README of the Pipeline Library repository. + Some parameters may not be supported at the moment, see the Pipeline code. +

+ + From 927f74639341b8dde70b57d693896f6e1494fdad Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Thu, 15 Aug 2019 11:45:35 +0200 Subject: [PATCH 2/9] Remove timestamps --- vars/buildPluginWithGradle.groovy | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vars/buildPluginWithGradle.groovy b/vars/buildPluginWithGradle.groovy index 34ad53ef5..cd697df2e 100644 --- a/vars/buildPluginWithGradle.groovy +++ b/vars/buildPluginWithGradle.groovy @@ -80,7 +80,5 @@ def call(Map params = [:]) { } } - timestamps { - parallel(tasks) - } + parallel(tasks) } From 96e5b9416a204dcfc374c61b7139fcc0e4641171 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Thu, 15 Aug 2019 11:46:49 +0200 Subject: [PATCH 3/9] Update buildPluginWithGradle.groovy --- vars/buildPluginWithGradle.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildPluginWithGradle.groovy b/vars/buildPluginWithGradle.groovy index cd697df2e..9ac9b4b0b 100644 --- a/vars/buildPluginWithGradle.groovy +++ b/vars/buildPluginWithGradle.groovy @@ -21,7 +21,7 @@ def call(Map params = [:]) { boolean publishingIncrementals = false boolean archivedArtifacts = false Map tasks = [failFast: failFast] - buildPlugin.getConfigurations(params, true).each { config -> + buildPlugin.getConfigurations(params).each { config -> String label = config.platform String jdk = config.jdk String jenkinsVersion = config.jenkins From 7370ddf92de3e4ffa5edaebe140f61f27fc86c4f Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Thu, 15 Aug 2019 11:55:20 +0200 Subject: [PATCH 4/9] Apply suggestions from code review by @darxriggs --- vars/buildPluginWithGradle.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vars/buildPluginWithGradle.groovy b/vars/buildPluginWithGradle.groovy index 9ac9b4b0b..cfd7e634f 100644 --- a/vars/buildPluginWithGradle.groovy +++ b/vars/buildPluginWithGradle.groovy @@ -13,7 +13,7 @@ def call(Map params = [:]) { def repo = params.containsKey('repo') ? params.repo : null def failFast = params.containsKey('failFast') ? params.failFast : true def timeoutValue = params.containsKey('timeout') ? params.timeout : 60 - if(timeoutValue > 180) { + if (timeoutValue > 180) { echo "Timeout value requested was $timeoutValue, lowering to 180 to avoid Jenkins project's resource abusive consumption" timeoutValue = 180 } @@ -44,11 +44,11 @@ def call(Map params = [:]) { stage("Build (${stageIdentifier})") { if (javaLevel != null) { - echo "WARNING: java.level is not supported in the buildGradlePlugin(). This parmeter will be ignored" + echo "WARNING: 'javaLevel' parameter is not supported in buildPluginWithGradle(). It will be ignored" } //TODO(oleg-nenashev): Once supported by Gradle JPI Plugin, pass jenkinsVersion if (jenkinsVersion != null) { - echo "WARNING: Jenkins version is not supported in buildGradlePlugin(). This parmeter will be ignored" + echo "WARNING: 'jenkinsVersion' parameter is not supported in buildPluginWithGradle(). It will be ignored" } List gradleOptions = [ '--no-daemon', From 8bbca67834281d08a5ee22a0a965f3edf12da874 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Sat, 17 Aug 2019 10:04:07 +0200 Subject: [PATCH 5/9] README: Add documentation for buildPluginWithGradle() --- README.adoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.adoc b/README.adoc index 4313350ef..ca606b520 100644 --- a/README.adoc +++ b/README.adoc @@ -121,6 +121,20 @@ see the step doc for more documentation about he allowed versions infra.stashJenkinsWar("2.110") ---- +=== buildPluginWithGradle() + +Builds a Jenkins plugin using Gradle. +The implementation follows the standard build/test/archive pattern. +The method targets compatibility with [Gradle JPI Plugin](https://github.com/jenkinsci/gradle-jpi-plugin), +and it may not work for other use-cases. + +The interface is similar to `buildPlugin()`, but some features are not supported. +Examples of not supported features: + +* [JEP-305](https://github.com/jenkinsci/jep/tree/master/jep/305) +* Publushing of static analysis and coverage reports (Checkstyle, SpotBugs, JaCoCo) +* Configuring `jenkinsVersion` and `javaLevel` for the build flow + === runATH Runs the link:https://github.com/jenkinsci/acceptance-test-harness[Acceptance Test Harness] in a configurable way. From b4e56aa07a18d04f8be30747243edf3f4857fabb Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Sun, 18 Aug 2019 10:49:10 +0200 Subject: [PATCH 6/9] Update README.adoc --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index ca606b520..91d683ba1 100644 --- a/README.adoc +++ b/README.adoc @@ -132,7 +132,7 @@ The interface is similar to `buildPlugin()`, but some features are not supported Examples of not supported features: * [JEP-305](https://github.com/jenkinsci/jep/tree/master/jep/305) -* Publushing of static analysis and coverage reports (Checkstyle, SpotBugs, JaCoCo) +* Publishing of static analysis and coverage reports (Checkstyle, SpotBugs, JaCoCo) * Configuring `jenkinsVersion` and `javaLevel` for the build flow === runATH From f2a1d97ed421f7f9753abbea8bafb7c8800600c7 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Tue, 20 Aug 2019 12:37:21 +0200 Subject: [PATCH 7/9] Use Asciidoc instead of Markdown --- README.adoc | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/README.adoc b/README.adoc index 91d683ba1..bc610f83a 100644 --- a/README.adoc +++ b/README.adoc @@ -9,8 +9,7 @@ Check link:https://github.com/jenkins-infra/documentation/blob/master/ci.adoc[th === buildPlugin -| WARNING: Gradle support in `buildPlugin()` is deprecated and will be eventually removed. Please use `buildPluginWithGradle()` | -| --- | +WARNING: Gradle support in `buildPlugin()` is deprecated and will be eventually removed. Please use `buildPluginWithGradle()` Applies the appropriate defaults for building a Maven-based plugin project on Linux and Windows. @@ -85,6 +84,20 @@ Usage: buildPlugin(platforms: ['linux'], jdkVersions: [7, 8], findbugs: [archive: true, unstableTotalAll: '0'], checkstyle: [run: true, archive: true]) ---- +=== buildPluginWithGradle() + +Builds a Jenkins plugin using Gradle. +The implementation follows the standard build/test/archive pattern. +The method targets compatibility with link:https://github.com/jenkinsci/gradle-jpi-plugin[Gradle JPI Plugin], +and it may not work for other use-cases. + +The interface is similar to `buildPlugin()`, but some features are not supported. +Examples of not supported features: + +* Deployment of incremental versions (link:https://github.com/jenkinsci/jep/tree/master/jep/305[JEP-305]) +* Publishing of static analysis and coverage reports (Checkstyle, SpotBugs, JaCoCo) +* Configuring `jenkinsVersion` and `javaLevel` for the build flow + === infra.isTrusted() Determine whether the Pipeline is executing in an internal "trusted" Jenkins @@ -121,20 +134,6 @@ see the step doc for more documentation about he allowed versions infra.stashJenkinsWar("2.110") ---- -=== buildPluginWithGradle() - -Builds a Jenkins plugin using Gradle. -The implementation follows the standard build/test/archive pattern. -The method targets compatibility with [Gradle JPI Plugin](https://github.com/jenkinsci/gradle-jpi-plugin), -and it may not work for other use-cases. - -The interface is similar to `buildPlugin()`, but some features are not supported. -Examples of not supported features: - -* [JEP-305](https://github.com/jenkinsci/jep/tree/master/jep/305) -* Publishing of static analysis and coverage reports (Checkstyle, SpotBugs, JaCoCo) -* Configuring `jenkinsVersion` and `javaLevel` for the build flow - === runATH Runs the link:https://github.com/jenkinsci/acceptance-test-harness[Acceptance Test Harness] in a configurable way. From 7ccbf039fc95af76bb2ab577d3b8b619d7ae7be3 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Tue, 20 Aug 2019 13:05:39 +0200 Subject: [PATCH 8/9] Add Gradle step documentation to the root --- README.adoc | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index bc610f83a..c5d2c9d84 100644 --- a/README.adoc +++ b/README.adoc @@ -91,12 +91,39 @@ The implementation follows the standard build/test/archive pattern. The method targets compatibility with link:https://github.com/jenkinsci/gradle-jpi-plugin[Gradle JPI Plugin], and it may not work for other use-cases. -The interface is similar to `buildPlugin()`, but some features are not supported. +==== Optional arguments + +* `repo` (default: `null` inherit from Multibranch) - custom Git repository to check out +* `failFast` (default: `true`) - instruct the build to fail fast when one of the configurations fail +* `platforms` (default: `['linux', 'windows']`) - Labels matching platforms to + execute the steps against in parallel +* `jdkVersions` (default: `[8]`) - JDK version numbers, must match a version + number jdk tool installed +* `configurations`: An alternative way to specify `platforms`, `jdkVersions` (that can not be combined + with any of them) +** Those options will run the build for all combinations of their values. While that is desirable in + many cases, `configurations` permit to provide a specific combinations of label and java/jenkins versions to use +** It is also possible to use a `buildPlugin.recommendedConfigurations()` method to get recommended configurations for testing. +Note that the recommended configuration may change over time, +and hence your CI may break if the new recommended configuration is not compatible + +[source,groovy] +---- +buildPlugin(/*...*/, configurations: [ + [ platform: "linux", jdk: "8"], + [ platform: "windows", jdk: "8"], +]) +---- + +==== Limitations + +Not all features of `buildPlugin()` for Maven are supported in the gradle flow. Examples of not supported features: * Deployment of incremental versions (link:https://github.com/jenkinsci/jep/tree/master/jep/305[JEP-305]) * Publishing of static analysis and coverage reports (Checkstyle, SpotBugs, JaCoCo) -* Configuring `jenkinsVersion` and `javaLevel` for the build flow +* Configuring `jenkinsVersion` and `javaLevel` for the build flow (as standalone arguments or as `configurations`) +* Usage of link:https://azure.microsoft.com/en-us/services/container-instances/[Azure Container Instances] as agents (only Maven agents are configured) === infra.isTrusted() From 5a1e71c921a864326d84e1f1795b51ff2d7cc58e Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Wed, 28 Aug 2019 18:50:39 +0200 Subject: [PATCH 9/9] Apply suggestions from code review from @darxriggs --- README.adoc | 6 +++--- vars/buildPluginWithGradle.txt | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.adoc b/README.adoc index c5d2c9d84..2bf2056d0 100644 --- a/README.adoc +++ b/README.adoc @@ -106,11 +106,11 @@ and it may not work for other use-cases. ** It is also possible to use a `buildPlugin.recommendedConfigurations()` method to get recommended configurations for testing. Note that the recommended configuration may change over time, and hence your CI may break if the new recommended configuration is not compatible - +* `timeout`: (default: `60`) - the number of minutes for build timeout, cannot be bigger than 180, i.e. 3 hours. [source,groovy] ---- -buildPlugin(/*...*/, configurations: [ - [ platform: "linux", jdk: "8"], +buildPluginWithGradle(/*...*/, configurations: [ + [ platform: "linux", jdk: "8" ], [ platform: "windows", jdk: "8"], ]) ---- diff --git a/vars/buildPluginWithGradle.txt b/vars/buildPluginWithGradle.txt index e06e108c1..c0313eccf 100644 --- a/vars/buildPluginWithGradle.txt +++ b/vars/buildPluginWithGradle.txt @@ -11,7 +11,6 @@

Usage. The method can be used in the same way as buildPlugin() for Maven projects. See the documentation in the README of the Pipeline Library repository. - Some parameters may not be supported at the moment, see the Pipeline code.