From 73ddda19b688c778b8bcd9b412fcfaf7ddbc8a5a Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Fri, 8 Mar 2019 08:58:19 +0100 Subject: [PATCH 01/33] Offer recommended configurations for buildPlugin() --- README.adoc | 16 ++++++++++++++-- vars/buildPlugin.groovy | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index b7b7232c1..38a24e273 100644 --- a/README.adoc +++ b/README.adoc @@ -31,9 +31,10 @@ buildPlugin() * `jenkinsVersions`: (default: `[null]`) - a matrix of Jenkins baseline versions to build/test against in parallel (null means default, only available for Maven projects) * `configurations`: An alternative way to specify `platforms`, `jdkVersions` and `jenkinsVersions` (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 + 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: - + [source,groovy] ---- buildPlugin(/*...*/, configurations: [ @@ -42,6 +43,17 @@ buildPlugin(/*...*/, configurations: [ [ platform: "linux", jdk: "11", jenkins: "2.150", javaLevel: 8 ] ]) ---- + +** 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: buildPlugin.recommendedConfigurations()) +---- + + * `tests`: (default: `null`) - a map of parameters to run tests during the build ** `skip` - If `true`, skipp all the tests by setting the `-skipTests` profile. It will also skip FindBugs in modern Plugin POMs. diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index 88113bf95..501a55953 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -219,3 +219,21 @@ static List> getConfigurations(Map params) { } return ret } + +/** + * Get recommended configurations for testing. + * Includes testing Java 8 and 11 on the newest LTS. + */ +static List> recommendedConfigurations() { + //TODO: replace by 2.164.1 once it is released + def recentLTS = "2.164" + def configurations = [ + [ platform: "linux", jdk: "8", jenkins: null ], + [ platform: "windows", jdk: "8", jenkins: null ], + [ platform: "linux", jdk: "8", jenkins: recentLTS, javaLevel: "8" ], + [ platform: "windows", jdk: "8", jenkins: recentLTS, javaLevel: "8" ], + [ platform: "linux", jdk: "11", jenkins: recentLTS, javaLevel: "8" ], + [ platform: "windows", jdk: "11", jenkins: recentLTS, javaLevel: "8" ] + ] + return configurations +} From 7952f63a576e11449d1462d181329bf19c533977 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Mon, 18 Mar 2019 13:58:53 +0100 Subject: [PATCH 02/33] buildPlugin() - Switch to the LTS release --- vars/buildPlugin.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index 501a55953..bfcf4a017 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -225,8 +225,7 @@ static List> getConfigurations(Map params) { * Includes testing Java 8 and 11 on the newest LTS. */ static List> recommendedConfigurations() { - //TODO: replace by 2.164.1 once it is released - def recentLTS = "2.164" + def recentLTS = "2.164.1" def configurations = [ [ platform: "linux", jdk: "8", jenkins: null ], [ platform: "windows", jdk: "8", jenkins: null ], From 4b8289669e1942c308177a9ebbb3e2788f1eba6d Mon Sep 17 00:00:00 2001 From: Chris Kilding Date: Wed, 15 May 2019 11:13:11 +0100 Subject: [PATCH 03/33] Archive Maven Failsafe Plugin reports --- .gitignore | 2 +- vars/buildPlugin.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7eac4b491..336378772 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.sw* build/ - +.idea \ No newline at end of file diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index bfcf4a017..43865b76b 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -115,7 +115,7 @@ def call(Map params = [:]) { if (!skipTests) { String testReports if (isMaven) { - testReports = '**/target/surefire-reports/**/*.xml' + testReports = '**/target/surefire-reports/**/*.xml,**/target/failsafe-reports/**/*.xml' } else { testReports = '**/build/test-results/**/*.xml' } From a4390b26cbe30263033a3dab639b1d3d46dff442 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 31 May 2019 15:17:45 -0400 Subject: [PATCH 04/33] [INFRA-2028] The timestamps step is no longer necessary. --- vars/buildPlugin.groovy | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index bfcf4a017..e1b0751cc 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -171,11 +171,9 @@ def call(Map params = [:]) { } } - timestamps { - parallel(tasks) - if (publishingIncrementals) { - infra.maybePublishIncrementals() - } + parallel(tasks) + if (publishingIncrementals) { + infra.maybePublishIncrementals() } } From 1a320f4aff1bbf7cb0998d8bb3d577ee7a9d3def Mon Sep 17 00:00:00 2001 From: Abhyudaya Sharma Date: Mon, 10 Jun 2019 12:24:28 +0530 Subject: [PATCH 05/33] Add function to run JMH benchmarks --- README.adoc | 16 ++++++++++++++++ vars/runBenchmarks.groovy | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 vars/runBenchmarks.groovy diff --git a/README.adoc b/README.adoc index 38a24e273..37d57863c 100644 --- a/README.adoc +++ b/README.adoc @@ -357,6 +357,22 @@ pct: "default" *Please note that a blank metadata file will result in an error* +=== runBenchmarks + +Runs JMH benchmarks and archives benchmark reports on `highmem` nodes. + +Supported parameters: + +`artifacts`:: +(Optional) If `artifacts` is not null, invokes `archiveArtifacts` with the given string value. + + +===== Example +[source, groovy] +---- +runBenchmarks('jmh-report.json') +---- + === Design documents for runATH and runPCT The design and some more details about the runATH and runPCT steps can be found link:https://wiki.jenkins.io/display/JENKINS/runATH+and+runPCT+step+design[here] diff --git a/vars/runBenchmarks.groovy b/vars/runBenchmarks.groovy new file mode 100644 index 000000000..f0d88233e --- /dev/null +++ b/vars/runBenchmarks.groovy @@ -0,0 +1,29 @@ +#!/usr/bin/env groovy + +/** + * Run JMH benchmarks and archives results + * @param artifacts archive these JMH reports + * @since TODO + */ +def call(String artifacts = null) { + // TODO: Use Lockable Resources plugin + node('highmem') { + + stage('Checkout repo') { + infra.checkout() + } + + stage('Run Benchmarks') { + List mvnOptions = ['test', '-Dbenchmark'] + infra.runMaven(mvnOptions) + } + + stage('Archive reports') { + if (artifacts != null) { + archiveArtifacts artifacts: artifacts + } else { + echo 'No artifacts to archive, skipping...' + } + } + } +} From e2875743ea3244ab5f888dd21e13158dbcc4e003 Mon Sep 17 00:00:00 2001 From: Abhyudaya Sharma Date: Mon, 10 Jun 2019 16:26:06 +0530 Subject: [PATCH 06/33] Add HTML documentation for `runBenchmarks` --- vars/runBenchmarks.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 vars/runBenchmarks.txt diff --git a/vars/runBenchmarks.txt b/vars/runBenchmarks.txt new file mode 100644 index 000000000..ad9e3d1ac --- /dev/null +++ b/vars/runBenchmarks.txt @@ -0,0 +1,22 @@ +

+ Runs JMH benchmarks and archives benchmark reports on highmem nodes. +

+

+ Supported Parameters: +

+ +
+
artifacts
+
+ (Optional) If artifacts is not null, invokes archiveArtifacts + with the given string value. +
+
+ +

+ Example: +

+ +
+    runBenchmarks('jmh-report.json')
+
From de61bc7dc93a6307320641bd598da4b5035cd5f3 Mon Sep 17 00:00:00 2001 From: Abhyudaya Sharma Date: Wed, 12 Jun 2019 10:16:19 +0530 Subject: [PATCH 07/33] Use 'runBenchmark' resource to throttle benchmark builds --- vars/runBenchmarks.groovy | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/vars/runBenchmarks.groovy b/vars/runBenchmarks.groovy index f0d88233e..4805400de 100644 --- a/vars/runBenchmarks.groovy +++ b/vars/runBenchmarks.groovy @@ -6,23 +6,24 @@ * @since TODO */ def call(String artifacts = null) { - // TODO: Use Lockable Resources plugin - node('highmem') { + lock('runBenchmarks') { + node('highmem') { - stage('Checkout repo') { - infra.checkout() - } + stage('Checkout repo') { + infra.checkout() + } - stage('Run Benchmarks') { - List mvnOptions = ['test', '-Dbenchmark'] - infra.runMaven(mvnOptions) - } + stage('Run Benchmarks') { + List mvnOptions = ['test', '-Dbenchmark'] + infra.runMaven(mvnOptions) + } - stage('Archive reports') { - if (artifacts != null) { - archiveArtifacts artifacts: artifacts - } else { - echo 'No artifacts to archive, skipping...' + stage('Archive reports') { + if (artifacts != null) { + archiveArtifacts artifacts: artifacts + } else { + echo 'No artifacts to archive, skipping...' + } } } } From 802f4f4f38ecd8b403d266429f55495ba012bffb Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 12 Jun 2019 22:47:20 +0100 Subject: [PATCH 08/33] feature: enable jenkins-pipeline-unit --- .gitignore | 1 + Jenkinsfile | 33 ++++++ pom.xml | 152 +++++++++++++++++++++++++ src/test/groovy/InfraStepTests.groovy | 153 ++++++++++++++++++++++++++ 4 files changed, 339 insertions(+) create mode 100644 Jenkinsfile create mode 100644 pom.xml create mode 100644 src/test/groovy/InfraStepTests.groovy diff --git a/.gitignore b/.gitignore index 7eac4b491..9b23b65d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.sw* build/ +target diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..1e5f2f812 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,33 @@ +#!/usr/bin/env groovy + +pipeline { + agent { + label "java" + } + tools { + maven 'mvn' + jdk 'jdk8' + } + options { + timestamps() + } + + stages { + stage('Checkout') { + steps { + deleteDir() + checkout scm + } + } + stage('Test') { + steps { + sh 'mvn clean test' + } + post { + always { + junit(keepLongStdio: true, testResults: "target/surefire-reports/junit-*.xml,target/surefire-reports/TEST-*.xml") + } + } + } + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..382ed1e90 --- /dev/null +++ b/pom.xml @@ -0,0 +1,152 @@ + + + + org.jenkins-ci.plugins + plugin + 3.40 + + 4.0.0 + io.jenkins.infra + pipeline-library + 0.0.1 + + Jenkins Pipeline Shared Library + Pipeline Shared Library containing utility steps. + https://github.com/jenkins-infra/pipeline-library + + + true + 2.176.1 + 8 + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + The MIT license + http://www.opensource.org/licenses/mit-license.php + repo + + + + + scm:git:git://github.com/jenkins-infra/pipeline-library.git + scm:git:ssh://git@github.com/jenkins-infra/pipeline-library.git + + + + + junit + junit + 4.12 + test + + + com.lesfurets + jenkins-pipeline-unit + 1.1 + test + + + org.codehaus.groovy + groovy-all + + + commons-io + commons-io + + + + + + + src + + + resources + + + + + org.codehaus.gmaven + gmaven-plugin + 1.5 + + + + generateStubs + compile + generateTestStubs + testCompile + + + + + 2.0 + + + ${project.basedir}/src/test/groovy + + *.groovy + + + + ${project.basedir}/vars + + *.groovy + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.12 + + + add-test-source + generate-sources + + add-test-source + + + + src/test/groovy + vars + src + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M1 + + + + + diff --git a/src/test/groovy/InfraStepTests.groovy b/src/test/groovy/InfraStepTests.groovy new file mode 100644 index 000000000..cb77528ee --- /dev/null +++ b/src/test/groovy/InfraStepTests.groovy @@ -0,0 +1,153 @@ +import com.lesfurets.jenkins.unit.BasePipelineTest +import org.junit.Before +import org.junit.Ignore +import org.junit.Test +import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.junit.Assert.assertTrue +import static org.junit.Assert.assertFalse + +class InfraStepTests extends BasePipelineTest { + static final String scriptName = "vars/infra.groovy" + Map env = [:] + + @Override + @Before + void setUp() throws Exception { + super.setUp() + + env.JENKINS_URL = 'https://ci.jenkins.io/' + binding.setVariable('env', env) + binding.setProperty('scm', new String()) + binding.setProperty('mvnSettingsFile', 'settings.xml') + + helper.registerAllowedMethod('checkout', [String.class], { 'OK' }) + helper.registerAllowedMethod('configFile', [Map.class], { 'OK' }) + helper.registerAllowedMethod('configFileProvider', [List.class, Closure.class], { list, closure -> + def res = closure.call() + return res + }) + helper.registerAllowedMethod('echo', [String.class], { s -> s }) + helper.registerAllowedMethod('error', [String.class], {s -> + updateBuildStatus('FAILURE') + throw new Exception(s) + }) + helper.registerAllowedMethod('git', [String.class], { 'OK' }) + helper.registerAllowedMethod("isUnix", [], { true }) + helper.registerAllowedMethod('sh', [String.class], { s -> s }) + helper.registerAllowedMethod('withCredentials', [List.class, Closure.class], { list, closure -> + def res = closure.call() + return res + }) + } + + @Test + void testIsRunningOnJenkinsInfra() throws Exception { + println 'testIsRunningOnJenkinsInfra' + def script = loadScript(scriptName) + assertTrue(script.isRunningOnJenkinsInfra()) + } + + @Test + void testIsTrusted() throws Exception { + println 'testIsTrusted' + + def script = loadScript(scriptName) + env.JENKINS_URL = 'https://trusted.ci.jenkins.io:1443/' + binding.setVariable('env', env) + assertTrue(script.isTrusted()) + } + + @Test + void testWithDockerCredentials() throws Exception { + println 'testWithDockerCredentials' + def script = loadScript(scriptName) + helper.registerAllowedMethod("isRunningOnJenkinsInfra", [ ], { true }) + helper.registerAllowedMethod("isTrusted", [ ], { true }) + + def isOK = false + script.withDockerCredentials() { + isOK = true + } + printCallStack() + assertTrue(isOK) + assertJobStatusSuccess() + } + + @Test + void testWithDockerCredentialsOutsideInfra() throws Exception { + println 'testWithDockerCredentialsOutsideInfra' + def script = loadScript(scriptName) + helper.registerAllowedMethod('isRunningOnJenkinsInfra', [ ], { false }) + def isOK = false + script.withDockerCredentials() { + isOK = true + } + printCallStack() + /*assertTrue(helper.callStack.findAll { call -> + call.methodName == 'echo' + }.any { call -> + callArgsToString(call).contains('Cannot use Docker credentials outside of jenkins infra environment') + })*/ + assertJobStatusSuccess() + } + + @Test + @Ignore("Some stackoverflow issues") + void testCheckoutWithEnvVariable() throws Exception { + println 'testCheckoutWithEnvVariable' + def script = loadScript(scriptName) + env.BRANCH_NAME = 'BRANCH' + script.checkout() + printCallStack() + assertJobStatusSuccess() + } + + @Test + void testCheckoutWithArgument() throws Exception { + println 'testCheckoutWithArgument' + def script = loadScript(scriptName) + script.checkout('foo.git') + printCallStack() + assertJobStatusSuccess() + } + + @Test + void testCheckoutWithoutArgument() throws Exception { + println 'testCheckoutWithoutArgument' + def script = loadScript(scriptName) + try { + script.checkout() + } catch(e){ + //NOOP + } + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'error' + }.any { call -> + callArgsToString(call).contains('buildPlugin must be used as part of a Multibranch Pipeline') + }) + assertJobStatusFailure() + } + + @Test + void testRetrieveMavenSettingsFileWithEnvVariable() throws Exception { + println 'retrieveMavenSettingsFile' + def script = loadScript(scriptName) + env.MAVEN_SETTINGS_FILE_ID = 'foo.id' + def result = script.retrieveMavenSettingsFile('foo.xml') + assertTrue(result) + printCallStack() + assertJobStatusSuccess() + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'sh' + }.any { call -> + callArgsToString(call).contains('settings.xml foo.xml') + }) + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'configFile' + }.any { call -> + callArgsToString(call).contains('foo.id') + }) + } + +} From 05349d1b3a0c3415255d754d647bc7b85b021944 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 13 Jun 2019 12:04:37 +0100 Subject: [PATCH 09/33] Simplify POM as stated here: https://github.com/jenkinsci/archetypes/blob/master/scripted-pipeline/src/main/resources/archetype-resources/pom.xml --- pom.xml | 225 ++++++++++++++++++++------------------------------------ 1 file changed, 79 insertions(+), 146 deletions(-) diff --git a/pom.xml b/pom.xml index 382ed1e90..62b9e758d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,152 +1,85 @@ - - - org.jenkins-ci.plugins - plugin - 3.40 - - 4.0.0 - io.jenkins.infra - pipeline-library - 0.0.1 + + 4.0.0 + io.jenkins.infra + pipeline-library + 0.0.1 + Jenkins Pipeline Shared Library + Pipeline Shared Library containing utility steps. + https://github.com/jenkins-infra/pipeline-library - Jenkins Pipeline Shared Library - Pipeline Shared Library containing utility steps. - https://github.com/jenkins-infra/pipeline-library + + + MIT License + http://opensource.org/licenses/MIT + + - - true - 2.176.1 - 8 - + + scm:git:git://github.com/jenkins-infra/pipeline-library.git + scm:git:ssh://git@github.com/jenkins-infra/pipeline-library.git + - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - + + 1.8 + 1.8 + - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - - The MIT license - http://www.opensource.org/licenses/mit-license.php - repo - - - - - scm:git:git://github.com/jenkins-infra/pipeline-library.git - scm:git:ssh://git@github.com/jenkins-infra/pipeline-library.git - - - - - junit - junit - 4.12 - test - - - com.lesfurets - jenkins-pipeline-unit - 1.1 - test - - - org.codehaus.groovy - groovy-all - - - commons-io - commons-io - - - - - - - src - - - resources - - - - - org.codehaus.gmaven - gmaven-plugin - 1.5 - - - - generateStubs - compile - generateTestStubs - testCompile - - - - - 2.0 - - - ${project.basedir}/src/test/groovy - - *.groovy - - - - ${project.basedir}/vars - - *.groovy - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.12 - - - add-test-source - generate-sources - - add-test-source - - - - src/test/groovy - vars - src - - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.1.0 - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M1 - - - - + + + org.codehaus.groovy + groovy-all + 2.4.3 + test + + + junit + junit + 4.12 + test + + + com.lesfurets + jenkins-pipeline-unit + 1.1 + test + + + + vars + src + + + resources + + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.9.2-01 + true + + + maven-compiler-plugin + + groovy-eclipse-compiler + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.9.2-01 + + + + org.codehaus.groovy + groovy-eclipse-batch + 2.4.3-01 + + + + + From fe20103043de537beacceaa20dc6e902dd0d3d2f Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 13 Jun 2019 22:15:44 +0100 Subject: [PATCH 10/33] Revert "Simplify POM as stated here: https://github.com/jenkinsci/archetypes/blob/master/scripted-pipeline/src/main/resources/archetype-resources/pom.xml" This reverts commit 05349d1b3a0c3415255d754d647bc7b85b021944. --- pom.xml | 225 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 146 insertions(+), 79 deletions(-) diff --git a/pom.xml b/pom.xml index 62b9e758d..382ed1e90 100644 --- a/pom.xml +++ b/pom.xml @@ -1,85 +1,152 @@ - - 4.0.0 - io.jenkins.infra - pipeline-library - 0.0.1 - Jenkins Pipeline Shared Library - Pipeline Shared Library containing utility steps. - https://github.com/jenkins-infra/pipeline-library + + + org.jenkins-ci.plugins + plugin + 3.40 + + 4.0.0 + io.jenkins.infra + pipeline-library + 0.0.1 - - - MIT License - http://opensource.org/licenses/MIT - - + Jenkins Pipeline Shared Library + Pipeline Shared Library containing utility steps. + https://github.com/jenkins-infra/pipeline-library - - scm:git:git://github.com/jenkins-infra/pipeline-library.git - scm:git:ssh://git@github.com/jenkins-infra/pipeline-library.git - + + true + 2.176.1 + 8 + - - 1.8 - 1.8 - + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + - - - org.codehaus.groovy - groovy-all - 2.4.3 - test - - - junit - junit - 4.12 - test - - - com.lesfurets - jenkins-pipeline-unit - 1.1 - test - - - - vars - src - - - resources - - - - - org.codehaus.groovy - groovy-eclipse-compiler - 2.9.2-01 - true - - - maven-compiler-plugin - - groovy-eclipse-compiler - - - - org.codehaus.groovy - groovy-eclipse-compiler - 2.9.2-01 - - - - org.codehaus.groovy - groovy-eclipse-batch - 2.4.3-01 - - - - - + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + The MIT license + http://www.opensource.org/licenses/mit-license.php + repo + + + + + scm:git:git://github.com/jenkins-infra/pipeline-library.git + scm:git:ssh://git@github.com/jenkins-infra/pipeline-library.git + + + + + junit + junit + 4.12 + test + + + com.lesfurets + jenkins-pipeline-unit + 1.1 + test + + + org.codehaus.groovy + groovy-all + + + commons-io + commons-io + + + + + + + src + + + resources + + + + + org.codehaus.gmaven + gmaven-plugin + 1.5 + + + + generateStubs + compile + generateTestStubs + testCompile + + + + + 2.0 + + + ${project.basedir}/src/test/groovy + + *.groovy + + + + ${project.basedir}/vars + + *.groovy + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.12 + + + add-test-source + generate-sources + + add-test-source + + + + src/test/groovy + vars + src + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M1 + + + + From 1d6af8329b815550de3479973b305a93f1e072e3 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 13 Jun 2019 22:57:00 +0100 Subject: [PATCH 11/33] UTs for the publishReports step --- .../groovy/PublishReportsStepTests.groovy | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/test/groovy/PublishReportsStepTests.groovy diff --git a/src/test/groovy/PublishReportsStepTests.groovy b/src/test/groovy/PublishReportsStepTests.groovy new file mode 100644 index 000000000..3effd6ded --- /dev/null +++ b/src/test/groovy/PublishReportsStepTests.groovy @@ -0,0 +1,128 @@ +import com.lesfurets.jenkins.unit.BasePipelineTest +import org.junit.Before +import org.junit.Test +import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertTrue + +class PublishReportsStepTests extends BasePipelineTest { + static final String scriptName = 'vars/publishReports.groovy' + Map env = [:] + + /** + * Mock Infra step + */ + class Infra implements Serializable { + private final boolean result + public Infra(boolean result) { this.result = result } + public boolean isTrusted() { return result } + } + + /** + * Mock Docker class from docker-workflow plugin. + */ + class Docker implements Serializable { + public Image image(String id) { new Image(this, id) } + public class Image implements Serializable { + private Image(Docker docker, String id) {} + public V inside(String args = '', Closure body) { body() } + } + } + + @Override + @Before + void setUp() throws Exception { + super.setUp() + + binding.setVariable('env', env) + binding.setProperty('docker', new Docker()) + binding.setProperty('infra', new Infra(true)) + + helper.registerAllowedMethod('error', [String.class], {s -> + updateBuildStatus('FAILURE') + throw new Exception(s) + }) + helper.registerAllowedMethod('sh', [String.class], { s -> s }) + helper.registerAllowedMethod('withCredentials', [List.class, Closure.class], { list, body -> body() }) + helper.registerAllowedMethod('withEnv', [List.class, Closure.class], { list, body -> body() }) + } + + @Test + void test_without_trusted_infra() throws Exception { + def script = loadScript(scriptName) + binding.setProperty('infra', new Infra(false)) + // when running with !infra.isTrusted() + try { + script.call(null) + } catch(e){ + //NOOP + } + printCallStack() + // then an error is thrown + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'error' + }.any { call -> + callArgsToString(call).contains('Can only call publishReports from within the trusted.ci environment') + }) + assertJobStatusFailure() + } + + @Test + void test_with_trusted_and_empty_infra() throws Exception { + def script = loadScript(scriptName) + // when running with an empty list and infra.isTrusted() + script.call([]) + printCallStack() + // then hardcoded credentials is correct + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'string' + }.any { call -> + callArgsToString(call).contains('credentialsId=azure-reports-access-key') + }) + // No execution + assertTrue(helper.callStack.findAll { call -> call.methodName == 'sh' }.isEmpty()) + assertJobStatusSuccess() + } + + @Test + void test_with_trusted_and_html_infra() throws Exception { + def script = loadScript(scriptName) + // when running with a html filename + script.call([ 'foo.html' ]) + printCallStack() + // then timeout is default and filename manipulations is in place + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'sh' + }.any { call -> + callArgsToString(call).contains('--timeout=60 --file=foo.html --name=foo.html --content-type="text/html"') + }) + // another filename manipulations is in place + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'sh' + }.any { call -> + callArgsToString(call).trim().replaceAll(" +", " ").contains('--source . --destination-path / --pattern foo.html --content-type="text/html"') + }) + assertJobStatusSuccess() + } + + @Test + void test_with_trusted_and_full_path_css_infra() throws Exception { + def script = loadScript(scriptName) + // when running with a css full path filename + script.call([ '/bar/foo.css' ]) + printCallStack() + // then timeout is default and filename manipulations is in place + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'sh' + }.any { call -> + callArgsToString(call).contains('--timeout=60 --file=/bar/foo.css --name=/bar/foo.css --content-type="text/css"') + }) + // another filename manipulations is in place + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'sh' + }.any { call -> + callArgsToString(call).trim().replaceAll(" +", " ").contains('--source /bar --destination-path /bar --pattern foo.css --content-type="text/css"') + }) + assertJobStatusSuccess() + } +} From d47a39f2a6a38a3bf1413f364e7f125a7e6aa9d2 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 14 Jun 2019 21:05:36 +0100 Subject: [PATCH 12/33] Revert "Revert "Simplify POM as stated here: https://github.com/jenkinsci/archetypes/blob/master/scripted-pipeline/src/main/resources/archetype-resources/pom.xml"" This reverts commit fe20103043de537beacceaa20dc6e902dd0d3d2f. --- pom.xml | 225 ++++++++++++++++++++------------------------------------ 1 file changed, 79 insertions(+), 146 deletions(-) diff --git a/pom.xml b/pom.xml index 382ed1e90..62b9e758d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,152 +1,85 @@ - - - org.jenkins-ci.plugins - plugin - 3.40 - - 4.0.0 - io.jenkins.infra - pipeline-library - 0.0.1 + + 4.0.0 + io.jenkins.infra + pipeline-library + 0.0.1 + Jenkins Pipeline Shared Library + Pipeline Shared Library containing utility steps. + https://github.com/jenkins-infra/pipeline-library - Jenkins Pipeline Shared Library - Pipeline Shared Library containing utility steps. - https://github.com/jenkins-infra/pipeline-library + + + MIT License + http://opensource.org/licenses/MIT + + - - true - 2.176.1 - 8 - + + scm:git:git://github.com/jenkins-infra/pipeline-library.git + scm:git:ssh://git@github.com/jenkins-infra/pipeline-library.git + - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - + + 1.8 + 1.8 + - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - - The MIT license - http://www.opensource.org/licenses/mit-license.php - repo - - - - - scm:git:git://github.com/jenkins-infra/pipeline-library.git - scm:git:ssh://git@github.com/jenkins-infra/pipeline-library.git - - - - - junit - junit - 4.12 - test - - - com.lesfurets - jenkins-pipeline-unit - 1.1 - test - - - org.codehaus.groovy - groovy-all - - - commons-io - commons-io - - - - - - - src - - - resources - - - - - org.codehaus.gmaven - gmaven-plugin - 1.5 - - - - generateStubs - compile - generateTestStubs - testCompile - - - - - 2.0 - - - ${project.basedir}/src/test/groovy - - *.groovy - - - - ${project.basedir}/vars - - *.groovy - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.12 - - - add-test-source - generate-sources - - add-test-source - - - - src/test/groovy - vars - src - - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.1.0 - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M1 - - - - + + + org.codehaus.groovy + groovy-all + 2.4.3 + test + + + junit + junit + 4.12 + test + + + com.lesfurets + jenkins-pipeline-unit + 1.1 + test + + + + vars + src + + + resources + + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.9.2-01 + true + + + maven-compiler-plugin + + groovy-eclipse-compiler + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.9.2-01 + + + + org.codehaus.groovy + groovy-eclipse-batch + 2.4.3-01 + + + + + From 6f60756049f6620675efddbbef4796094fca0175 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 17 Jun 2019 22:05:13 +0100 Subject: [PATCH 13/33] Remove println as it's not required and finish the UT for testWithDockerCredentialsOutsideInfra implementation as it does use the env variables --- src/test/groovy/InfraStepTests.groovy | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/test/groovy/InfraStepTests.groovy b/src/test/groovy/InfraStepTests.groovy index cb77528ee..4bad4a993 100644 --- a/src/test/groovy/InfraStepTests.groovy +++ b/src/test/groovy/InfraStepTests.groovy @@ -15,7 +15,6 @@ class InfraStepTests extends BasePipelineTest { void setUp() throws Exception { super.setUp() - env.JENKINS_URL = 'https://ci.jenkins.io/' binding.setVariable('env', env) binding.setProperty('scm', new String()) binding.setProperty('mvnSettingsFile', 'settings.xml') @@ -42,15 +41,13 @@ class InfraStepTests extends BasePipelineTest { @Test void testIsRunningOnJenkinsInfra() throws Exception { - println 'testIsRunningOnJenkinsInfra' def script = loadScript(scriptName) + env.JENKINS_URL = 'https://ci.jenkins.io/' assertTrue(script.isRunningOnJenkinsInfra()) } @Test void testIsTrusted() throws Exception { - println 'testIsTrusted' - def script = loadScript(scriptName) env.JENKINS_URL = 'https://trusted.ci.jenkins.io:1443/' binding.setVariable('env', env) @@ -59,11 +56,8 @@ class InfraStepTests extends BasePipelineTest { @Test void testWithDockerCredentials() throws Exception { - println 'testWithDockerCredentials' def script = loadScript(scriptName) - helper.registerAllowedMethod("isRunningOnJenkinsInfra", [ ], { true }) - helper.registerAllowedMethod("isTrusted", [ ], { true }) - + env.JENKINS_URL = 'https://ci.jenkins.io/' def isOK = false script.withDockerCredentials() { isOK = true @@ -75,26 +69,25 @@ class InfraStepTests extends BasePipelineTest { @Test void testWithDockerCredentialsOutsideInfra() throws Exception { - println 'testWithDockerCredentialsOutsideInfra' def script = loadScript(scriptName) - helper.registerAllowedMethod('isRunningOnJenkinsInfra', [ ], { false }) + env.JENKINS_URL = 'https://foo/' def isOK = false script.withDockerCredentials() { isOK = true } printCallStack() - /*assertTrue(helper.callStack.findAll { call -> + assertFalse(isOK) + assertTrue(helper.callStack.findAll { call -> call.methodName == 'echo' }.any { call -> callArgsToString(call).contains('Cannot use Docker credentials outside of jenkins infra environment') - })*/ + }) assertJobStatusSuccess() } @Test @Ignore("Some stackoverflow issues") void testCheckoutWithEnvVariable() throws Exception { - println 'testCheckoutWithEnvVariable' def script = loadScript(scriptName) env.BRANCH_NAME = 'BRANCH' script.checkout() @@ -104,7 +97,6 @@ class InfraStepTests extends BasePipelineTest { @Test void testCheckoutWithArgument() throws Exception { - println 'testCheckoutWithArgument' def script = loadScript(scriptName) script.checkout('foo.git') printCallStack() @@ -113,7 +105,6 @@ class InfraStepTests extends BasePipelineTest { @Test void testCheckoutWithoutArgument() throws Exception { - println 'testCheckoutWithoutArgument' def script = loadScript(scriptName) try { script.checkout() @@ -131,7 +122,6 @@ class InfraStepTests extends BasePipelineTest { @Test void testRetrieveMavenSettingsFileWithEnvVariable() throws Exception { - println 'retrieveMavenSettingsFile' def script = loadScript(scriptName) env.MAVEN_SETTINGS_FILE_ID = 'foo.id' def result = script.retrieveMavenSettingsFile('foo.xml') From d49d456fa6e422acea54e2b0460e4d1c77198ea0 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 18 Jun 2019 18:07:54 +0100 Subject: [PATCH 14/33] UTs for the essentialsTest step --- pom.xml | 6 + .../groovy/EssentialsTestStepTests.groovy | 207 ++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 src/test/groovy/EssentialsTestStepTests.groovy diff --git a/pom.xml b/pom.xml index 62b9e758d..ccae8227b 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,12 @@ 1.1 test + + org.yaml + snakeyaml + 1.21 + test + vars diff --git a/src/test/groovy/EssentialsTestStepTests.groovy b/src/test/groovy/EssentialsTestStepTests.groovy new file mode 100644 index 000000000..b9df9eb8a --- /dev/null +++ b/src/test/groovy/EssentialsTestStepTests.groovy @@ -0,0 +1,207 @@ +import com.lesfurets.jenkins.unit.BasePipelineTest +import org.yaml.snakeyaml.Yaml +import org.junit.Before +import org.junit.Test +import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.junit.Assert.assertTrue +import static org.junit.Assert.assertFalse + +class EssentialsTestStepTests extends BasePipelineTest { + static final String scriptName = 'vars/essentialsTest.groovy' + Map env = [:] + + /** + * Mock Infra step + */ + class Infra implements Serializable { + public void checkout() { } + } + + /** + * Mock customWARPackager step + */ + class CustomWARPackager implements Serializable { + public void build(String path, String war, String bom) { } + } + + static final String essentials = ''' +flow: + ath: + testPluginResolution: + skipOnUnmetDependencies: true +ath: + disabled: false +pct: + disabled: false + ''' + + static final String essentials_with_disabled_skipOnUnmetDependencies = ''' +flow: + ath: + testPluginResolution: + skipOnUnmetDependencies: false +ath: + disabled: false +pct: + disabled: false + ''' + + static final String essentials_with_disabled_ath_and_pct = ''' + flow: + ath: + testPluginResolution: + skipOnUnmetDependencies: false + ath: + disabled: true + pct: + disabled: true + ''' + + @Override + @Before + void setUp() throws Exception { + super.setUp() + + Yaml yaml1 = new Yaml() + println yaml1.load(essentials) + binding.setVariable('env', env) + binding.setProperty('customWARPackager', new CustomWARPackager()) + binding.setProperty('infra', new Infra()) + + helper.registerAllowedMethod('dir', [String.class], { s -> s }) + helper.registerAllowedMethod('node', [String.class], { s -> s }) + helper.registerAllowedMethod('pwd', [], { '/foo' }) + helper.registerAllowedMethod('pwd', [Map.class], { '/bar' }) + helper.registerAllowedMethod('readYaml', [Map.class], { + Yaml yaml = new Yaml() + return yaml.load(essentials) + }) + + helper.registerAllowedMethod('runATH', [Map.class], { }) + helper.registerAllowedMethod('runPCT', [Map.class], { }) + } + + @Test + void test_default_parameters() throws Exception { + def script = loadScript(scriptName) + // when running with !infra.isTrusted() + script.call() + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'node' + }.any { call -> + callArgsToString(call).contains('docker && highmem') + }) + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'dir' + }.any { call -> + callArgsToString(call).contains('.,') + }) + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'readYaml' + }.any { call -> + callArgsToString(call).contains('/foo/essentials.yml') + }) + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'runATH' + }.any { call -> + callArgsToString(call).contains('jenkins=file:///bar/custom.war, metadataFile=/foo/essentials.yml') + }) + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'runPCT' + }.any { call -> + callArgsToString(call).contains('jenkins=file:///bar/custom.war, metadataFile=/foo/essentials.yml') + }) + } + + @Test + void test_with_baseDir_parameters() throws Exception { + def script = loadScript(scriptName) + script.call(baseDir: '/another') + printCallStack() + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'dir' + }.any { call -> + callArgsToString(call).contains('/another') + }) + } + + @Test + void test_with_metadataFile_parameters() throws Exception { + def script = loadScript(scriptName) + script.call(metadataFile: 'myfile.yml') + printCallStack() + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'readYaml' + }.any { call -> + callArgsToString(call).contains('/foo/myfile.yml') + }) + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'runATH' + }.any { call -> + callArgsToString(call).contains('metadataFile=/foo/myfile.yml') + }) + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'runATH' + }.any { call -> + callArgsToString(call).contains('skipOnInvalid') + }) + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'runPCT' + }.any { call -> + callArgsToString(call).contains('metadataFile=/foo/myfile.yml') + }) + } + + @Test + void test_with_labels_parameters() throws Exception { + def script = loadScript(scriptName) + script.call(labels: 'mylabel') + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'node' + }.any { call -> + callArgsToString(call).contains('mylabel') + }) + } + + @Test + void test_default_parameters_with_disabled_skipOnUnmetDependencies() throws Exception { + def script = loadScript(scriptName) + helper.registerAllowedMethod('readYaml', [Map.class], { + Yaml yaml = new Yaml() + return yaml.load(essentials_with_disabled_skipOnUnmetDependencies) + }) + script.call() + printCallStack() + + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'runATH' + }.any { call -> + callArgsToString(call).contains('failOnInvalid') + }) + } + + @Test + void test_default_parameters_with_disabed_ath_and_pct() throws Exception { + def script = loadScript(scriptName) + helper.registerAllowedMethod('readYaml', [Map.class], { + Yaml yaml = new Yaml() + return yaml.load(essentials_with_disabled_ath_and_pct) + }) + script.call() + printCallStack() + assertFalse(helper.callStack.any { call -> call.methodName == 'runATH' }) + assertFalse(helper.callStack.any { call -> call.methodName == 'runPCT' }) + } + +} From 2d35fafa2fdf4de413208fd801378cb46500d3e0 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 18 Jun 2019 18:08:45 +0100 Subject: [PATCH 15/33] Remove unnecessary debug traces --- src/test/groovy/EssentialsTestStepTests.groovy | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/groovy/EssentialsTestStepTests.groovy b/src/test/groovy/EssentialsTestStepTests.groovy index b9df9eb8a..0c3fa3a52 100644 --- a/src/test/groovy/EssentialsTestStepTests.groovy +++ b/src/test/groovy/EssentialsTestStepTests.groovy @@ -62,8 +62,6 @@ pct: void setUp() throws Exception { super.setUp() - Yaml yaml1 = new Yaml() - println yaml1.load(essentials) binding.setVariable('env', env) binding.setProperty('customWARPackager', new CustomWARPackager()) binding.setProperty('infra', new Infra()) From b25f101f65803a8aa50f45de637d350406d4a5d0 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 18 Jun 2019 21:29:25 +0100 Subject: [PATCH 16/33] UTs for the CustomWarPackage step: it does cover some basic use cases --- .../groovy/CustomWARPackagerStepTests.groovy | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 src/test/groovy/CustomWARPackagerStepTests.groovy diff --git a/src/test/groovy/CustomWARPackagerStepTests.groovy b/src/test/groovy/CustomWARPackagerStepTests.groovy new file mode 100644 index 000000000..7d07ae320 --- /dev/null +++ b/src/test/groovy/CustomWARPackagerStepTests.groovy @@ -0,0 +1,171 @@ +import com.lesfurets.jenkins.unit.BasePipelineTest +import org.junit.Before +import org.junit.Test +import org.yaml.snakeyaml.Yaml +import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.junit.Assert.assertTrue + +class CustomWARPackagerStepTests extends BasePipelineTest { + static final String scriptName = 'vars/customWARPackager.groovy' + Map env = [:] + + static final String without_packaging_metadata = ''' + bar: true + ''' + + static final String without_packaging_config_metadata = ''' + packaging: + bom: true + environment: true + jdk: 7 + cwpVersion: "1.2.3" + archiveArtifacts: false + installArtifacts: false + ''' + + static final String without_bom_config_metadata = ''' + packaging: + config: true + environment: true + jdk: 7 + cwpVersion: "1.2.3" + archiveArtifacts: false + installArtifacts: false + metadata: + config: true + ''' + + static final String default_config_metadata = ''' + packaging: + config: true + environment: true + jdk: 7 + cwpVersion: "1.2.3" + archiveArtifacts: false + installArtifacts: false + metadata: + labels: + version: "foo" + artifactId: "barId" + ''' + + /** + * Mock Infra step + */ + class Infra implements Serializable { + public String retrieveMavenSettingsFile(String location) { return location } + public String runWithMaven(String cmd) { return cmd } + public String runMaven(mvn, jdk, foo, settings) { return 'OK' } + } + + @Override + @Before + void setUp() throws Exception { + super.setUp() + + binding.setProperty('infra', new Infra()) + binding.setVariable('env', env) + + helper.registerAllowedMethod('archiveArtifacts', [Map.class], { m -> m }) + helper.registerAllowedMethod('echo', [String.class], { s -> s }) + helper.registerAllowedMethod('error', [String.class], {s -> + updateBuildStatus('FAILURE') + throw new Exception(s) + }) + helper.registerAllowedMethod('findFiles', [Map.class], { String[] files = ["bom.yml", "d1/bom.yml"] }) + helper.registerAllowedMethod('pwd', [], { '/foo' }) + helper.registerAllowedMethod('pwd', [Map.class], { '/bar' }) + helper.registerAllowedMethod('readYaml', [Map.class], { + Yaml yaml = new Yaml() + return yaml.load(default_config_metadata) + }) + helper.registerAllowedMethod('sh', [String.class], { s -> s }) + helper.registerAllowedMethod('writeYaml', [Map.class], { }) + } + + @Test + void test_without_packaging() throws Exception { + def script = loadScript(scriptName) + helper.registerAllowedMethod('readYaml', [Map.class], { + Yaml yaml = new Yaml() + return yaml.load(without_packaging_metadata) + }) + // when running without metadata.packaging + try { + script.build('metadataFile', 'outputWAR', 'outputBOM', 'settings') + } catch(e){ + //NOOP + } + printCallStack() + // then an error is thrown + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'error' + }.any { call -> + callArgsToString(call).contains("No 'packaging' section in the metadata file metadataFile") + }) + assertJobStatusFailure() + } + + @Test + void test_without_packaging_config() throws Exception { + def script = loadScript(scriptName) + helper.registerAllowedMethod('readYaml', [Map.class], { + Yaml yaml = new Yaml() + return yaml.load(without_packaging_config_metadata) + }) + // when running without metadata.packaging + try { + script.build('metadataFile', 'outputWAR', 'outputBOM', 'settings') + } catch(e){ + //NOOP + } + printCallStack() + // then an error is thrown + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'error' + }.any { call -> + callArgsToString(call).contains("packaging.config or packaging.configFile must be defined") + }) + assertJobStatusFailure() + } + + @Test + void test_without_bom_config() throws Exception { + def script = loadScript(scriptName) + helper.registerAllowedMethod('readYaml', [Map.class], { m -> + Yaml yaml = new Yaml() + return yaml.load(without_bom_config_metadata) + }) + script.build('metadataFile', 'outputWAR', 'outputBOM', 'settings') + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'echo' + }.any { call -> + callArgsToString(call).contains("BOM file is not explicitly defined, but there is bom.yml in the root. Using it") + }) + assertJobStatusSuccess() + } + + @Test + void test_default_config() throws Exception { + def script = loadScript(scriptName) + script.build('metadataFile', 'outputWAR', 'outputBOM', 'settings') + printCallStack() + + // then the war file with the artifact id and label from the metadata is copied + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'sh' + }.any { call -> + callArgsToString(call).contains('cp barId-foo.war') + }) + + // then the yaml file with the artifact id and label from the metadata is copied + assertTrue(helper.callStack.findAll { call -> + call.methodName == 'sh' + }.any { call -> + callArgsToString(call).contains('cp barId-foo.bom.yml') + }) + assertJobStatusSuccess() + } + +} From 57b4a70fb3f1857c130f0ca8633dae13786ea00a Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 2 Jul 2019 21:05:58 +0100 Subject: [PATCH 17/33] As suggested: removed duplicated checkout, background execution of the mvn goals and use the default surefire pattern --- Jenkinsfile | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1e5f2f812..823b21d55 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,4 @@ #!/usr/bin/env groovy - pipeline { agent { label "java" @@ -11,21 +10,14 @@ pipeline { options { timestamps() } - stages { - stage('Checkout') { - steps { - deleteDir() - checkout scm - } - } stage('Test') { steps { - sh 'mvn clean test' + sh 'mvn -B clean test' } post { always { - junit(keepLongStdio: true, testResults: "target/surefire-reports/junit-*.xml,target/surefire-reports/TEST-*.xml") + junit(keepLongStdio: true, testResults: 'target/surefire-reports/TEST-*.xml') } } } From 875e54bbcff05a23475441721ea5944f48a6df11 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 2 Jul 2019 21:12:14 +0100 Subject: [PATCH 18/33] use the latest archetype --- pom.xml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index ccae8227b..ca784a16d 100644 --- a/pom.xml +++ b/pom.xml @@ -24,25 +24,30 @@ 1.8 1.8 + + 2.4.17 + 4.12 + 1.1 + 3.4.0-01 org.codehaus.groovy groovy-all - 2.4.3 + ${groovy.version} test junit junit - 4.12 + ${junit.version} test com.lesfurets jenkins-pipeline-unit - 1.1 + ${jenkins-pipeline-unit.version} test @@ -53,22 +58,23 @@ - vars - src + src/test/groovy resources + vars org.codehaus.groovy groovy-eclipse-compiler - 2.9.2-01 + ${groovy-eclipse-compiler.version} true maven-compiler-plugin + 3.8.1 groovy-eclipse-compiler @@ -76,13 +82,13 @@ org.codehaus.groovy groovy-eclipse-compiler - 2.9.2-01 + ${groovy-eclipse-compiler.version} org.codehaus.groovy groovy-eclipse-batch - 2.4.3-01 + 2.5.7-01 From ba1396adea9a074006a411c25f6523d519d08c36 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 2 Jul 2019 21:18:33 +0100 Subject: [PATCH 19/33] Let's force the version 3.0.0 as it does use 'maven-surefire-plugin:2.12.4:test' by default with the latest changes --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index ca784a16d..a97931bd4 100644 --- a/pom.xml +++ b/pom.xml @@ -92,6 +92,11 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M3 + From 04d1de4c68b0209b0c82e41803dfc5332b3ae938 Mon Sep 17 00:00:00 2001 From: Alex Earl Date: Tue, 30 Jul 2019 09:10:28 -0700 Subject: [PATCH 20/33] Use ACI agents for Linux based builds. --- vars/buildPlugin.groovy | 7 ++++--- vars/infra.groovy | 32 ++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index bfcf4a017..b09db3c89 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -15,6 +15,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 + def useAci = params.containsKey('useAci') ? params.useAci : true if(timeoutValue > 180) { echo "Timeout value requested was $timeoutValue, lowering to 180 to avoid Jenkins project's resource abusive consumption" timeoutValue = 180 @@ -38,7 +39,7 @@ def call(Map params = [:]) { boolean skipTests = params?.tests?.skip tasks[stageIdentifier] = { - node(label) { + node((useAci && label == 'linux') ? (jdk == 8 ? 'maven' : 'maven-11') : label) { timeout(timeoutValue) { boolean isMaven // Archive artifacts once with pom declared baseline @@ -96,7 +97,7 @@ def call(Map params = [:]) { if (runCheckstyle) { mavenOptions += "checkstyle:checkstyle" } - infra.runMaven(mavenOptions, jdk) + infra.runMaven(mavenOptions, jdk, null, null, !useAci) } else { List gradleOptions = [ '--no-daemon', @@ -107,7 +108,7 @@ def call(Map params = [:]) { if (isUnix()) { command = "./" + command } - infra.runWithJava(command, jdk) + infra.runWithJava(command, jdk, null, !useAci) } } diff --git a/vars/infra.groovy b/vars/infra.groovy index 9d2048da2..5e2e64b6e 100644 --- a/vars/infra.groovy +++ b/vars/infra.groovy @@ -66,7 +66,7 @@ boolean retrieveMavenSettingsFile(String settingsXml, String jdk = 8) { * @return nothing * @see #retrieveMavenSettingsFile(String) */ -Object runMaven(List options, String jdk = 8, List extraEnv = null, String settingsFile = null) { +Object runMaven(List options, String jdk = 8, List extraEnv = null, String settingsFile = null, Boolean addToolEnv = true) { List mvnOptions = [ '--batch-mode', '--show-version', @@ -85,7 +85,7 @@ Object runMaven(List options, String jdk = 8, List extraEnv = nu mvnOptions.addAll(options) mvnOptions.unique() String command = "mvn ${mvnOptions.join(' ')}" - runWithMaven(command, jdk, extraEnv) + runWithMaven(command, jdk, extraEnv, addToolEnv) } /** @@ -96,15 +96,19 @@ Object runMaven(List options, String jdk = 8, List extraEnv = nu * @param extraEnv Extra environment variables to be passed * @return nothing */ -Object runWithMaven(String command, String jdk = 8, List extraEnv = null) { - List env = [ +Object runWithMaven(String command, String jdk = 8, List extraEnv = null, Boolean addToolEnv = true) { + List env = []; + if(addToolEnv) { + env = [ "PATH+MAVEN=${tool 'mvn'}/bin" - ] + ] + } + if (extraEnv != null) { env.addAll(extraEnv) } - runWithJava(command, jdk, env) + runWithJava(command, jdk, env, addToolEnv) } /** @@ -116,12 +120,16 @@ Object runWithMaven(String command, String jdk = 8, List extraEnv = null * @param extraEnv Extra environment variables to be passed * @return nothing */ -Object runWithJava(String command, String jdk = 8, List extraEnv = null) { - String jdkTool = "jdk${jdk}" - List env = [ - "JAVA_HOME=${tool jdkTool}", - 'PATH+JAVA=${JAVA_HOME}/bin', - ] +Object runWithJava(String command, String jdk = 8, List extraEnv = null, Boolean addToolEnv = true) { + List env = []; + if(addToolEnv) { + String jdkTool = "jdk${jdk}" + List env = [ + "JAVA_HOME=${tool jdkTool}", + 'PATH+JAVA=${JAVA_HOME}/bin', + ] + } + if (extraEnv != null) { env.addAll(extraEnv) } From 546473b36ad073a40d18613bf0c78321e9018e59 Mon Sep 17 00:00:00 2001 From: Alex Earl Date: Tue, 30 Jul 2019 09:55:37 -0700 Subject: [PATCH 21/33] Switch default to false, add doc for useAci Less YOLO, more rtfm --- README.adoc | 1 + vars/buildPlugin.groovy | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 37d57863c..271e28caf 100644 --- a/README.adoc +++ b/README.adoc @@ -23,6 +23,7 @@ buildPlugin() ==== Optional arguments * `repo` (default: `null` inherit from Multibranch) - custom Git repository to check out +* `useAci` (default: `false`) - uses link:https://azure.microsoft.com/en-us/services/container-instances/[Azure Container Instances] for build instead of link:https://azure.microsoft.com/en-us/services/virtual-machines/[Azure Virtual Machines]. * `failFast` (default: `true`) - instruct Maven tests to fail fast * `platforms` (default: `['linux', 'windows']`) - Labels matching platforms to execute the steps against in parallel diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index b09db3c89..536b19049 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -15,7 +15,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 - def useAci = params.containsKey('useAci') ? params.useAci : true + def useAci = params.containsKey('useAci') ? params.useAci : false if(timeoutValue > 180) { echo "Timeout value requested was $timeoutValue, lowering to 180 to avoid Jenkins project's resource abusive consumption" timeoutValue = 180 From 233c05eaf9bb6e46f8befa6af90bee8834d3b6fb Mon Sep 17 00:00:00 2001 From: Alex Earl Date: Wed, 31 Jul 2019 08:06:44 -0700 Subject: [PATCH 22/33] Fix syntax issue --- vars/infra.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/infra.groovy b/vars/infra.groovy index 5e2e64b6e..554f6ff4b 100644 --- a/vars/infra.groovy +++ b/vars/infra.groovy @@ -124,7 +124,7 @@ Object runWithJava(String command, String jdk = 8, List extraEnv = null, List env = []; if(addToolEnv) { String jdkTool = "jdk${jdk}" - List env = [ + env = [ "JAVA_HOME=${tool jdkTool}", 'PATH+JAVA=${JAVA_HOME}/bin', ] From 0c7ee1d788e88cdb5a634d0d4ed1f88d06a06db4 Mon Sep 17 00:00:00 2001 From: Alex Earl Date: Wed, 31 Jul 2019 08:10:03 -0700 Subject: [PATCH 23/33] Fix logic for non-Linux machines --- vars/buildPlugin.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index 536b19049..bc3c59eff 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -37,6 +37,7 @@ def call(Map params = [:]) { boolean archiveFindbugs = first && params?.findbugs?.archive boolean archiveCheckstyle = first && params?.checkstyle?.archive boolean skipTests = params?.tests?.skip + boolean addToolEnv = !(useAci && label == 'linux') tasks[stageIdentifier] = { node((useAci && label == 'linux') ? (jdk == 8 ? 'maven' : 'maven-11') : label) { @@ -97,7 +98,7 @@ def call(Map params = [:]) { if (runCheckstyle) { mavenOptions += "checkstyle:checkstyle" } - infra.runMaven(mavenOptions, jdk, null, null, !useAci) + infra.runMaven(mavenOptions, jdk, null, null, addToolEnv) } else { List gradleOptions = [ '--no-daemon', @@ -108,7 +109,7 @@ def call(Map params = [:]) { if (isUnix()) { command = "./" + command } - infra.runWithJava(command, jdk, null, !useAci) + infra.runWithJava(command, jdk, null, addToolEnv) } } From 5a87fa45f826e1f85b2eafe83cfc57af8f03c6a3 Mon Sep 17 00:00:00 2001 From: Alex Earl Date: Wed, 31 Jul 2019 08:37:23 -0700 Subject: [PATCH 24/33] Fix check for jdk version The jdk variable is a string, not an int, fix the comparison --- vars/buildPlugin.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index bc3c59eff..40387a4ee 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -40,7 +40,7 @@ def call(Map params = [:]) { boolean addToolEnv = !(useAci && label == 'linux') tasks[stageIdentifier] = { - node((useAci && label == 'linux') ? (jdk == 8 ? 'maven' : 'maven-11') : label) { + node((useAci && label == 'linux') ? (jdk == "8" ? 'maven' : 'maven-11') : label) { timeout(timeoutValue) { boolean isMaven // Archive artifacts once with pom declared baseline From 47f6affb654df4216cba22c07b0ba95df8ffc43c Mon Sep 17 00:00:00 2001 From: Alex Earl Date: Wed, 31 Jul 2019 08:38:20 -0700 Subject: [PATCH 25/33] Use single quote to match other strings --- vars/buildPlugin.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index 40387a4ee..997e2f946 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -40,7 +40,7 @@ def call(Map params = [:]) { boolean addToolEnv = !(useAci && label == 'linux') tasks[stageIdentifier] = { - node((useAci && label == 'linux') ? (jdk == "8" ? 'maven' : 'maven-11') : label) { + node((useAci && label == 'linux') ? (jdk == '8' ? 'maven' : 'maven-11') : label) { timeout(timeoutValue) { boolean isMaven // Archive artifacts once with pom declared baseline From 6c992e1106e2624105cdfce377be10e2593d87b1 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 6 Aug 2019 07:43:46 +0100 Subject: [PATCH 26/33] Apply suggestions from code review Co-Authored-By: R. Tyler Croy --- Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 823b21d55..d2d339610 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,11 +1,9 @@ #!/usr/bin/env groovy pipeline { agent { - label "java" + label "maven" } tools { - maven 'mvn' - jdk 'jdk8' } options { timestamps() From a795368501c3b565eaf0b2fe53a73dc1aafa0838 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Mon, 12 Aug 2019 17:16:46 +0200 Subject: [PATCH 27/33] Enable Release Drafter for the repository --- .github/release-drafter.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/release-drafter.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 000000000..41afc5693 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,4 @@ +# See https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc +_extends: jenkinsci/.github +# Semantic versioning: https://semver.org/ +version-template: $MAJOR.$MINOR.$PATCH From 5b7046ebe4c841c784d4c54805ef26352044f954 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 13 Aug 2019 07:33:23 +0100 Subject: [PATCH 28/33] Cleanup plugin workspace after build --- vars/buildPlugin.groovy | 230 +++++++++++++++++++++------------------- 1 file changed, 119 insertions(+), 111 deletions(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index 997e2f946..ed0cb671d 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -41,132 +41,140 @@ def call(Map params = [:]) { tasks[stageIdentifier] = { node((useAci && label == 'linux') ? (jdk == '8' ? 'maven' : 'maven-11') : label) { - timeout(timeoutValue) { - boolean isMaven - // Archive artifacts once with pom declared baseline - boolean doArchiveArtifacts = !jenkinsVersion && !archivedArtifacts - if (doArchiveArtifacts) { - archivedArtifacts = true - } - boolean incrementals // cf. JEP-305 - - stage("Checkout (${stageIdentifier})") { - infra.checkout(repo) - isMaven = fileExists('pom.xml') - incrementals = fileExists('.mvn/extensions.xml') && - readFile('.mvn/extensions.xml').contains('git-changelist-maven-extension') - } + try { + timeout(timeoutValue) { + boolean isMaven + // Archive artifacts once with pom declared baseline + boolean doArchiveArtifacts = !jenkinsVersion && !archivedArtifacts + if (doArchiveArtifacts) { + archivedArtifacts = true + } + boolean incrementals // cf. JEP-305 - String changelistF - String m2repo - - stage("Build (${stageIdentifier})") { - String command - if (isMaven) { - m2repo = "${pwd tmp: true}/m2repo" - List mavenOptions = [ - '--update-snapshots', - "-Dmaven.repo.local=$m2repo", - '-Dmaven.test.failure.ignore', - ] - if (incrementals) { // set changelist and activate produce-incrementals profile - mavenOptions += '-Dset.changelist' - if (doArchiveArtifacts) { // ask Maven for the value of -rc999.abc123def456 - changelistF = "${pwd tmp: true}/changelist" - mavenOptions += "help:evaluate -Dexpression=changelist -Doutput=$changelistF" - } - } - if (jenkinsVersion) { - mavenOptions += "-Djenkins.version=${jenkinsVersion} -Daccess-modifier-checker.failOnError=false" - } - if (javaLevel) { - mavenOptions += "-Djava.level=${javaLevel}" - } - if (params?.findbugs?.run || params?.findbugs?.archive) { - mavenOptions += "-Dfindbugs.failOnError=false" - } - if (skipTests) { - mavenOptions += "-DskipTests" - } - if (params?.checkstyle?.run || params?.checkstyle?.archive) { - mavenOptions += "-Dcheckstyle.failOnViolation=false -Dcheckstyle.failsOnError=false" - } - mavenOptions += "clean install" - if (runFindbugs) { - mavenOptions += "findbugs:findbugs" - } - if (runCheckstyle) { - mavenOptions += "checkstyle:checkstyle" - } - infra.runMaven(mavenOptions, jdk, null, null, addToolEnv) - } else { - List gradleOptions = [ - '--no-daemon', - 'cleanTest', - 'build', - ] - command = "gradlew ${gradleOptions.join(' ')}" - if (isUnix()) { - command = "./" + command - } - infra.runWithJava(command, jdk, null, addToolEnv) + stage("Checkout (${stageIdentifier})") { + infra.checkout(repo) + isMaven = fileExists('pom.xml') + incrementals = fileExists('.mvn/extensions.xml') && + readFile('.mvn/extensions.xml').contains('git-changelist-maven-extension') } - } - stage("Archive (${stageIdentifier})") { - if (!skipTests) { - String testReports + String changelistF + String m2repo + + stage("Build (${stageIdentifier})") { + String command if (isMaven) { - testReports = '**/target/surefire-reports/**/*.xml' + m2repo = "${pwd tmp: true}/m2repo" + List mavenOptions = [ + '--update-snapshots', + "-Dmaven.repo.local=$m2repo", + '-Dmaven.test.failure.ignore', + ] + if (incrementals) { // set changelist and activate produce-incrementals profile + mavenOptions += '-Dset.changelist' + if (doArchiveArtifacts) { // ask Maven for the value of -rc999.abc123def456 + changelistF = "${pwd tmp: true}/changelist" + mavenOptions += "help:evaluate -Dexpression=changelist -Doutput=$changelistF" + } + } + if (jenkinsVersion) { + mavenOptions += "-Djenkins.version=${jenkinsVersion} -Daccess-modifier-checker.failOnError=false" + } + if (javaLevel) { + mavenOptions += "-Djava.level=${javaLevel}" + } + if (params?.findbugs?.run || params?.findbugs?.archive) { + mavenOptions += "-Dfindbugs.failOnError=false" + } + if (skipTests) { + mavenOptions += "-DskipTests" + } + if (params?.checkstyle?.run || params?.checkstyle?.archive) { + mavenOptions += "-Dcheckstyle.failOnViolation=false -Dcheckstyle.failsOnError=false" + } + mavenOptions += "clean install" + if (runFindbugs) { + mavenOptions += "findbugs:findbugs" + } + if (runCheckstyle) { + mavenOptions += "checkstyle:checkstyle" + } + infra.runMaven(mavenOptions, jdk, null, null, addToolEnv) } else { - testReports = '**/build/test-results/**/*.xml' + List gradleOptions = [ + '--no-daemon', + 'cleanTest', + 'build', + ] + command = "gradlew ${gradleOptions.join(' ')}" + if (isUnix()) { + command = "./" + command + } + infra.runWithJava(command, jdk, null, addToolEnv) } - junit testReports - // TODO do this in a finally-block so we capture all test results even if one branch aborts early } - if (isMaven && archiveFindbugs) { - def fp = [pattern: params?.findbugs?.pattern ?: '**/target/findbugsXml.xml'] - if (params?.findbugs?.unstableNewAll) { - fp['unstableNewAll'] = "${params.findbugs.unstableNewAll}" + + stage("Archive (${stageIdentifier})") { + if (!skipTests) { + String testReports + if (isMaven) { + testReports = '**/target/surefire-reports/**/*.xml' + } else { + testReports = '**/build/test-results/**/*.xml' + } + junit testReports + // TODO do this in a finally-block so we capture all test results even if one branch aborts early } - if (params?.findbugs?.unstableTotalAll) { - fp['unstableTotalAll'] = "${params.findbugs.unstableTotalAll}" + if (isMaven && archiveFindbugs) { + def fp = [pattern: params?.findbugs?.pattern ?: '**/target/findbugsXml.xml'] + if (params?.findbugs?.unstableNewAll) { + fp['unstableNewAll'] = "${params.findbugs.unstableNewAll}" + } + if (params?.findbugs?.unstableTotalAll) { + fp['unstableTotalAll'] = "${params.findbugs.unstableTotalAll}" + } + findbugs(fp) } - findbugs(fp) - } - if (isMaven && archiveCheckstyle) { - def cp = [pattern: params?.checkstyle?.pattern ?: '**/target/checkstyle-result.xml'] - if (params?.checkstyle?.unstableNewAll) { - cp['unstableNewAll'] = "${params.checkstyle.unstableNewAll}" + if (isMaven && archiveCheckstyle) { + def cp = [pattern: params?.checkstyle?.pattern ?: '**/target/checkstyle-result.xml'] + if (params?.checkstyle?.unstableNewAll) { + cp['unstableNewAll'] = "${params.checkstyle.unstableNewAll}" + } + if (params?.checkstyle?.unstableTotalAll) { + cp['unstableTotalAll'] = "${params.checkstyle.unstableTotalAll}" + } + checkstyle(cp) } - if (params?.checkstyle?.unstableTotalAll) { - cp['unstableTotalAll'] = "${params.checkstyle.unstableTotalAll}" + if (failFast && currentBuild.result == 'UNSTABLE') { + error 'There were test failures; halting early' } - checkstyle(cp) - } - if (failFast && currentBuild.result == 'UNSTABLE') { - error 'There were test failures; halting early' - } - if (doArchiveArtifacts) { - if (incrementals) { - String changelist = readFile(changelistF) - dir(m2repo) { - fingerprint '**/*-rc*.*/*-rc*.*' // includes any incrementals consumed - archiveArtifacts artifacts: "**/*$changelist/*$changelist*", - excludes: '**/*.lastUpdated', - allowEmptyArchive: true // in case we forgot to reincrementalify - } - publishingIncrementals = true - } else { - String artifacts - if (isMaven) { - artifacts = '**/target/*.hpi,**/target/*.jpi' + if (doArchiveArtifacts) { + if (incrementals) { + String changelist = readFile(changelistF) + dir(m2repo) { + fingerprint '**/*-rc*.*/*-rc*.*' // includes any incrementals consumed + archiveArtifacts artifacts: "**/*$changelist/*$changelist*", + excludes: '**/*.lastUpdated', + allowEmptyArchive: true // in case we forgot to reincrementalify + } + publishingIncrementals = true } else { - artifacts = '**/build/libs/*.hpi,**/build/libs/*.jpi' + String artifacts + if (isMaven) { + artifacts = '**/target/*.hpi,**/target/*.jpi' + } else { + artifacts = '**/build/libs/*.hpi,**/build/libs/*.jpi' + } + archiveArtifacts artifacts: artifacts, fingerprint: true } - archiveArtifacts artifacts: artifacts, fingerprint: true } } + } + } finally { + deleteDir() + + if (env?.NODE_LABELS?.contains("docker")) { + sh "docker system prune --force --all" } } } From 901b142e6838cf23bf7e84119ed0d8314e342716 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 13 Aug 2019 14:48:32 +0100 Subject: [PATCH 29/33] Don't fail on not being able to cleanup docker images --- vars/buildPlugin.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index ed0cb671d..3ae68de9b 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -173,8 +173,8 @@ def call(Map params = [:]) { } finally { deleteDir() - if (env?.NODE_LABELS?.contains("docker")) { - sh "docker system prune --force --all" + if (isUnix()) { + sh 'docker system prune --force --all || echo "Failed to cleanup docker images"' } } } From 9a9d61af7b481fc5bc4457c5ec59e6ae1dd9ae1b Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Tue, 13 Aug 2019 15:51:04 +0200 Subject: [PATCH 30/33] Jenkinsfile: remove the empty tools section from the Jenkinsfile --- Jenkinsfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d2d339610..a86163217 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,8 +3,6 @@ pipeline { agent { label "maven" } - tools { - } options { timestamps() } From 63c5586fe7d019259491f5be79c7898949b5e739 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 13 Aug 2019 14:59:34 +0100 Subject: [PATCH 31/33] Add || hasDockerLabel --- vars/buildPlugin.groovy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index 3ae68de9b..626fc62de 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -173,7 +173,7 @@ def call(Map params = [:]) { } finally { deleteDir() - if (isUnix()) { + if (isUnix() || hasDockerLabel()) { sh 'docker system prune --force --all || echo "Failed to cleanup docker images"' } } @@ -189,6 +189,10 @@ def call(Map params = [:]) { } } +static boolean hasDockerLabel() { + env?.NODE_LABELS?.contains("docker") +} + static List> getConfigurations(Map params) { boolean explicit = params.containsKey("configurations") boolean implicit = params.containsKey('platforms') || params.containsKey('jdkVersions') || params.containsKey('jenkinsVersions') From 59f4abade4754df9b5bc191e64086df7269042a6 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 13 Aug 2019 17:05:38 +0100 Subject: [PATCH 32/33] Remove static modifer --- vars/buildPlugin.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index 83bb8f4d2..b72c053e1 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -187,7 +187,7 @@ def call(Map params = [:]) { } } -static boolean hasDockerLabel() { +boolean hasDockerLabel() { env?.NODE_LABELS?.contains("docker") } From 97a0b0178742a21e4c9e25ff2ee5a2598f834700 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 13 Aug 2019 17:06:31 +0100 Subject: [PATCH 33/33] Remove unneeded null check --- vars/buildPlugin.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/buildPlugin.groovy b/vars/buildPlugin.groovy index b72c053e1..20279a306 100644 --- a/vars/buildPlugin.groovy +++ b/vars/buildPlugin.groovy @@ -188,7 +188,7 @@ def call(Map params = [:]) { } boolean hasDockerLabel() { - env?.NODE_LABELS?.contains("docker") + env.NODE_LABELS?.contains("docker") } static List> getConfigurations(Map params) {