Skip to content
Permalink
Browse files
make SonarCloud project key configurable
  • Loading branch information
kwin committed Oct 7, 2021
1 parent 9688d1d commit 2ba6c359d98344a6c6579ebb521f3d71e047efe5
Showing 2 changed files with 8 additions and 7 deletions.
@@ -8,10 +8,11 @@ It follows the structure outlined at <https://www.jenkins.io/doc/book/pipeline/s
It is supposed to be called in a `Jenkinsfile` like this

```
fileVaultMavenStdBuild([11, 8, 17], 11, [ "ubuntu", "Windows"], "ubuntu")
fileVaultMavenStdBuild([11, 8, 17], 11, [ "ubuntu", "Windows"], "ubuntu", "apache_jackrabbit-filevault")
```

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 main parameters specify on which environment the lengthy (environment independent) steps should happen like SonarQube analysis and optional deployment.
@@ -35,7 +35,7 @@ def executeMaven(String jdkLabel, String mavenArguments, String publisherStrateg
}
}

def buildStage(final int jdkVersion, final String nodeLabel, final boolean isMainBuild) {
def buildStage(final int jdkVersion, final String nodeLabel, final boolean isMainBuild, final String sonarProjektKey) {
return {
// 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']
@@ -70,7 +70,7 @@ def buildStage(final int jdkVersion, final String nodeLabel, final boolean isMai
stage("SonarCloud Analysis") {
timeout(60) {
withCredentials([string(credentialsId: 'sonarcloud-filevault-token', variable: 'SONAR_TOKEN')]) {
String mavenArguments = "${sonarPluginGav}:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache_jackrabbit-filevault"
String mavenArguments = "${sonarPluginGav}:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=${sonarProjectKey}"
executeMaven(jdkLabel, mavenArguments, 'IMPLICIT')
}
}
@@ -95,22 +95,22 @@ def buildStage(final int jdkVersion, final String nodeLabel, final boolean isMai
}
}

def stagesFor(List<Integer> jdkVersions, int mainJdkVersion, List<String> nodeLabels, String mainNodeLabel) {
def stagesFor(List<Integer> jdkVersions, int mainJdkVersion, List<String> nodeLabels, String mainNodeLabel, String sonarProjectKey) {
def stageMap = [:]
for (nodeLabel in nodeLabels) {
for (jdkVersion in jdkVersions) {
boolean isMainBuild = (jdkVersion == mainJdkVersion && nodeLabel == mainNodeLabel)
stageMap["JDK ${jdkVersion}, ${nodeLabel}${isMainBuild ? ' (Main)' : ''}"] = buildStage(jdkVersion, nodeLabel, isMainBuild)
stageMap["JDK ${jdkVersion}, ${nodeLabel}${isMainBuild ? ' (Main)' : ''}"] = buildStage(jdkVersion, nodeLabel, isMainBuild, sonarProjectKey)
}
}
return stageMap
}

// valid node labels in https://cwiki.apache.org/confluence/display/INFRA/ci-builds.apache.org
def call(List<Integer> jdkVersions, int mainJdkVersion, List<String> nodeLabels, String mainNodeLabel) {
def call(List<Integer> jdkVersions, int mainJdkVersion, List<String> nodeLabels, String mainNodeLabel, String sonarProjectKey) {
// adjust some job properties (https://www.jenkins.io/doc/pipeline/steps/workflow-multibranch/#properties-set-job-properties)
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10'))
])
parallel stagesFor(jdkVersions, mainJdkVersion, nodeLabels, mainNodeLabel)
parallel stagesFor(jdkVersions, mainJdkVersion, nodeLabels, mainNodeLabel, sonarProjectKey)
}

0 comments on commit 2ba6c35

Please sign in to comment.