From 1d2d01aa8cd2f15598889896964fc90472d2995f Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Mon, 7 May 2018 17:44:46 +0200 Subject: [PATCH] [INFRA-1459] - Initial implementation for the buildJenkinsComponent() step --- vars/buildJenkinsComponent.groovy | 66 +++++++++++++++++++++++++++++++ vars/buildJenkinsComponent.txt | 7 ++++ 2 files changed, 73 insertions(+) create mode 100644 vars/buildJenkinsComponent.groovy create mode 100644 vars/buildJenkinsComponent.txt diff --git a/vars/buildJenkinsComponent.groovy b/vars/buildJenkinsComponent.groovy new file mode 100644 index 000000000..084fe00df --- /dev/null +++ b/vars/buildJenkinsComponent.groovy @@ -0,0 +1,66 @@ +#!/usr/bin/env groovy + +/** + * Build a component defined by Jenkins parent POM. + * @param params Parameters to be passed + */ +def call(Map params = [:]) { + // These platforms correspond to labels in ci.jenkins.io, see: + // https://github.com/jenkins-infra/documentation/blob/master/ci.adoc + def platforms = params.containsKey('platforms') ? params.platforms : ['linux', 'windows'] + def jdkVersions = params.containsKey('jdkVersions') ? params.jdkVersions : [8] + int timeoutMin = params.containsKey('timeoutMin') ? Integer.parseInt(params.timeoutMin) : [8] + + Map branches = [:] + for (int i = 0; i < platforms.size(); ++i) { + String label = platforms[i] + for (int j = 0; j < jdkVersions.size(); ++j) { + String jdk = jdkVersions[j] + String stageIdentifier = "${label}${jdkVersions.size() > 1 ? '-' + jdk : ''}" + boolean first = i == 0 && j == 0 + branches[label] = { + buildSingle(stageIdentifier, label, jdk, first, timeoutMin) + } + } + } + + /* Execute our platforms in parallel */ + parallel(branches) +} + +/** + * Builds a single configuration of a component. + * @param stageIdentifier Stage identifier for visualization + * @param nodeLabel Node label + * @param jdk JDK to be used, {@code 8} by default + * @param archive If {@code true}, arhive results. + * {@code false} by default + * @param timeoutMin Timeout for the Maven run (in minutes) + * @return nothing + */ +def buildSingle(String stageIdentifier, String nodeLabel, String jdk = 8, boolean archive = false, int timeoutMin = 60) { + node(label) { + timeout(timeoutMin) { + timestamps { + stage("Checkout (${stageIdentifier})") { + infra.checkout(repo) + isMaven = fileExists('pom.xml') + } + + stage("Build (${stageIdentifier})") { + infra.runMaven(["--batch-mode", "clean", "install", "-Dmaven.test.failure.ignore=true"], jdk) + } + + stage("Archive (${stageIdentifier})") { + /* Archive the test results */ + junit '**/target/surefire-reports/TEST-*.xml' + + if (archive) { + archiveArtifacts artifacts: '**/target/**/*.jar' + findbugs pattern: '**/target/findbugsXml.xml' + } + } + } + } + } +} \ No newline at end of file diff --git a/vars/buildJenkinsComponent.txt b/vars/buildJenkinsComponent.txt new file mode 100644 index 000000000..2b5f841a0 --- /dev/null +++ b/vars/buildJenkinsComponent.txt @@ -0,0 +1,7 @@ +

+ Builds a Jenkins component following a standard build/test/archive pattern. See repository description for usage. +

+ +