in vars/vaultStageBuild.groovy [23:88]
def call(List<String> additionalNodeLabels, List<Integer> additionalJdkVersions, List<String> additionalMavenVersions, String sonarProjectKey, Map options=[:]) {
boolean hasSeparateItExecution = options.hasSeparateItExecution ?: false
String mainBuildArguments = options.mainBuildArguments ?: "-U clean site deploy -Pjacoco-report -Dlogback.configurationFile=vault-core/src/test/resources/logback-only-errors.xml"
String additionalBuildArguments = options.additionalBuildArguments ?: "-U clean ${hasSeparateItExecution?'package':'verify'} site"
PipelineSupport pipelineSupport = PipelineSupport.getInstance()
parallel pipelineSupport.stepsForMainAndAdditional('Maven Build', additionalNodeLabels.toSet(), additionalJdkVersions.toSet(), additionalMavenVersions.toSet(),
{ String nodeLabel, Integer jdkVersion, String mavenVersion, boolean isMainBuild ->
return {
final String sonarPluginGav = "org.sonarsource.scanner.maven:sonar-maven-plugin:4.0.0.4121"
node(label: nodeLabel) {
stage("${isMainBuild ? 'Main ' : ''}Maven Build (JDK ${jdkVersion}, Maven ${mavenVersion}, ${nodeLabel})") {
timeout(60) {
echo "Running on node ${env.NODE_NAME}"
checkout scm
try {
String mavenArguments
if (isMainBuild) {
String localRepoPath = "${env.WORKSPACE}/local-snapshots-dir"
// Make sure the directory is wiped.
dir(localRepoPath) {
deleteDir()
}
// main build with IT for properly calculating coverage
mavenArguments = "${mainBuildArguments} -DaltDeploymentRepository=snapshot-repo::default::file:${localRepoPath}"
} else {
mavenArguments = additionalBuildArguments
}
PipelineSupport.withSimpleCredentials(this, options.simpleCredentialsMap) {
PipelineSupport.executeMaven(this, jdkVersion, mavenVersion, mavenArguments, false)
}
if (isMainBuild) {
if (hasSeparateItExecution) {
// stash the integration test classes and the build artifact for later execution
stash name: 'integration-test-classes', includes: '**/target/test-classes/**,**/target/*.jar'
}
if (pipelineSupport.isOnMainBranch(env.BRANCH_NAME)) {
// Stash the build results so we can deploy them on another node
stash name: 'local-snapshots-dir', includes: 'local-snapshots-dir/**'
}
}
} catch (Throwable e) {
error 'Error during building ' + e.toString()
} finally {
junit '**/target/surefire-reports/**/*.xml,**/target/failsafe-reports*/**/*.xml'
}
}
}
if (isMainBuild) {
stage("SonarCloud Analysis") {
timeout(60) {
// always use Java 17 (https://docs.sonarcloud.io/appendices/scanner-environment/)
withCredentials([string(credentialsId: 'sonarcloud-filevault-token', variable: 'SONAR_TOKEN')]) {
String mavenArguments = "${sonarPluginGav}:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=${sonarProjectKey}"
// add variables for branch analysis: https://docs.sonarsource.com/sonarcloud/enriching/branch-analysis-setup/#setup-with-a-non-integrated-build-environment
if (!pipelineSupport.isOnMainBranch(env.BRANCH_NAME)) {
mavenArguments += " -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.branch.target=${pipelineSupport.getMainBranch()}"
}
pipelineSupport.executeMaven(this, 17, mavenArguments, false)
}
}
}
}
}
}
})
}