Skip to content
Permalink
Browse files
JCRVLT-580 allow to parameterize Maven version
separate IT execution
allow to configure each stage separately
  • Loading branch information
kwin committed Jan 7, 2022
1 parent ccbd996 commit 0643ca96faad4819fbeab55ac44f53591f746a78
Showing 9 changed files with 376 additions and 125 deletions.
@@ -1 +1,4 @@
/.project
/bin/
/.settings
/.classpath
@@ -4,15 +4,22 @@ This library is used for all FileVault Jenkins builds and enabled on <https://ci

It follows the structure outlined at <https://www.jenkins.io/doc/book/pipeline/shared-libraries/>


It is supposed to be called in a `Jenkinsfile` like this

```
fileVaultMavenStdBuild([11, 8, 17], 11, [ "ubuntu", "Windows"], "ubuntu", "apache_jackrabbit-filevault")
vaultPipeline('ubuntu', 11, '3', {
vaultStageBuild(['ubuntu', 'Windows'], [8, 11, 17], ['3', '3.6.3'], 'apache_jackrabbit-filevault-package-maven-plugin')
vaultStageDeploy()
}
)
```

The first argument is an array of JDK versions to build with, the second one the main JDK version.
The third argument is an array of node labels to build on, the fourth one the main node label.
The fifth argument is the SonarCloud project key.
The `vaultPipeline` step encapsulates the main build environment parameters:
The first argument is the main *node label* to build with, the second one the main *JDK version*, third argument the main *Maven version*
The fourth argument is a closure containing the actual stages where each may be one of

1. `vaultStageBuild`: the actual Maven build and SonarQube execution (the latter only for the main environment)
1. `vaultStageIT`: an isolated execution of just the integration tests
1. `vaultStageDeploy`: the stage to deploy the previously built Maven artifacts to the ASF Snapshot Repository (depends on 1.)

The main parameters specify on which environment the lengthy (environment independent) steps should happen like SonarQube analysis and optional deployment.
For the parametrisation of those individual stages refer the source code.
@@ -0,0 +1,49 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.jackrabbit.vault

class AsfCloudbeesJenkinsEnvironment {

// always major.minor.qualifier version parts or just one (which means latest of that major version)
public static String getMavenLabel(boolean isWindows, String mavenVersion) {
final String versionLabel
if (mavenVersion ==~ /\d+/) {
versionLabel = "${mavenVersion}_latest"
} else if (mavenVersion ==~ /\d+\.\d+\.\d+/) {
// make sure it
final String suffix
if (isWindows) {
suffix = "_windows"
} else {
suffix = ""
}
versionLabel = "${mavenVersion}${suffix}"
} else {
throw new IllegalArgumentException('mavenVersion must be either one integer or three integers separated by dot')
}
// valid installation names in https://cwiki.apache.org/confluence/display/INFRA/Maven+Installation+Matrix and https://github.com/apache/infrastructure-p6/blob/production/modules/jenkins_client_master/files/hudson.tasks.Maven.xml
return "maven_${versionLabel}"
}

public static String getJdkLabel(int jdkVersion) {
// https://cwiki.apache.org/confluence/display/INFRA/JDK+Installation+Matrix
def availableJDKs = [ 8: 'jdk_1.8_latest', 9: 'jdk_1.9_latest', 10: 'jdk_10_latest', 11: 'jdk_11_latest', 12: 'jdk_12_latest', 13: 'jdk_13_latest', 14: 'jdk_14_latest', 15: 'jdk_15_latest', 16: 'jdk_16_latest', 17: 'jdk_17_latest', 18: 'jdk_18_latest', 19: 'jdk_19_latest']
return availableJDKs[jdkVersion]
}
}
@@ -0,0 +1,89 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.jackrabbit.vault

/**
* Singleton class encapsulating information about main build environment and some helper methods.
*/
class PipelineSupport implements Serializable {

static PipelineSupport INSTANCE;

static PipelineSupport createInstance(String mainNodeLabel, int mainJdkVersion, String mainMavenVersion, boolean isOnMainBranch) {
INSTANCE = new PipelineSupport(mainNodeLabel, mainJdkVersion, mainMavenVersion, isOnMainBranch)
return INSTANCE
}

static PipelineSupport getInstance() {
if (INSTANCE == null) {
throw new IllegalStateException("createInstance has not been called before, not wrapped in vaultPipeline step?")
}
return INSTANCE;
}

private final String mainNodeLabel;
private final Integer mainJdkVersion;
private final String mainMavenVersion;
private final boolean isOnMainBranch;

PipelineSupport(String mainNodeLabel, int mainJdkVersion, String mainMavenVersion, boolean isOnMainBranch) {
this.mainNodeLabel = mainNodeLabel
this.mainJdkVersion = mainJdkVersion;
this.mainMavenVersion = mainMavenVersion
this.isOnMainBranch = isOnMainBranch
}

def executeMaven(pipeline, String mavenArguments, boolean enablePublishers) {
executeMaven(pipeline, mainJdkVersion, mainMavenVersion, mavenArguments, enablePublishers)
}

static def executeMaven(pipeline, Integer jdkVersion, String mavenVersion, String mavenArguments, boolean enablePublishers) {
pipeline.withMaven(
maven: AsfCloudbeesJenkinsEnvironment.getMavenLabel(!pipeline.isUnix(), mavenVersion),
jdk: AsfCloudbeesJenkinsEnvironment.getJdkLabel(jdkVersion),
mavenLocalRepo: '.repository',
publisherStrategy: enablePublishers?'IMPLICIT':'EXPLICIT') {
if (pipeline.isUnix()) {
pipeline.sh "mvn -B ${mavenArguments}"
} else {
pipeline.bat "mvn -B ${mavenArguments}"
}
}
}

def stepsForMainAndAdditional(String stepsLabel, Set<String> nodeLabels, Set<Integer> jdkVersions, Set<String> mavenVersions, Closure closure) {
stepsFor(stepsLabel, nodeLabels.plus(mainNodeLabel), jdkVersions.plus(mainJdkVersion), mavenVersions.plus(mainMavenVersion), closure, false)
}

def stepsFor(String stepsLabel, Set<String> nodeLabels, Set<Integer> jdkVersions, Set<String> mavenVersions, Closure closure, boolean excludeMain = false) {
def stepsMap = [:]
for (nodeLabel in nodeLabels) {
for (jdkVersion in jdkVersions) {
for (mavenVersion in mavenVersions) {
boolean isMainBuild = (nodeLabel.equals(mainNodeLabel) && jdkVersion.equals(mainJdkVersion) && mavenVersion.equals(mainMavenVersion))
if (excludeMain && isMainBuild) {
continue; // skip main environment
}
stepsMap["${stepsLabel} (JDK ${jdkVersion}, ${nodeLabel}, Maven ${mavenVersion}${isMainBuild ? ' (Main)' : ''})"] = closure(nodeLabel, jdkVersion, mavenVersion, isMainBuild)
}
}
}
return stepsMap
}
}

This file was deleted.

@@ -0,0 +1,40 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.jackrabbit.vault.PipelineSupport

// valid node labels in https://cwiki.apache.org/confluence/display/INFRA/ci-builds.apache.org
def call(String mainNodeLabel, int mainJdkVersion, String mainMavenVersion, Closure body) {
PipelineSupport pipelineSupport = PipelineSupport.createInstance(mainNodeLabel, mainJdkVersion, mainMavenVersion, env.BRANCH_NAME == 'master')
// adjust some job properties (https://www.jenkins.io/doc/pipeline/steps/workflow-multibranch/#properties-set-job-properties)
def buildProperties = []
if (pipelineSupport.isOnMainBranch) {
echo "Building main branch ${env.BRANCH_NAME}"
// set build retention time first
buildProperties.add(buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '5', daysToKeepStr: '15', numToKeepStr: '10')))
// ensure a build is done every month
buildProperties.add(pipelineTriggers([cron('@monthly')]))
} else {
echo "Building auxiliary branch ${env.BRANCH_NAME}"
buildProperties.add(buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '2', daysToKeepStr: '7', numToKeepStr: '3')))
}
properties(buildProperties)
body()
}

0 comments on commit 0643ca9

Please sign in to comment.