Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
JCRVLT-580 allow to parameterize Maven version
separate IT execution allow to configure each stage separately
- Loading branch information
Showing
9 changed files
with
376 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1 +1,4 @@ | ||
/.project | ||
/bin/ | ||
/.settings | ||
/.classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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() | ||
} | ||
|
Oops, something went wrong.