--- /dev/null
+---
+- project:
+ name: example-sonarcloud
+ jobs:
+ - gerrit-maven-sonar
+
+ project: 'sonarcloud'
+ project-name: 'sonarcloud'
+ branch: 'master'
+ mvn-settings: 'sonarcloud-settings'
+ mvn-opts: '-Xmx1024m'
+ sonarcloud: true
+ sonarcloud-project-key: KEY
+ sonarcloud-project-organization: ORGANIZATION
+ sonarcloud-api-token: TOKEN
:mvn-version: Version of Maven to execute Sonar with.
:mvn-settings: Maven settings.xml file containing credentials to use.
+lf-infra-maven-sonarcloud
+-------------------------
+
+Runs Sonar against a Maven project and pushes results to SonarCloud.
+
+:Required Parameters:
+
+ :java-version: Version of Java to execute Sonar with.
+ :mvn-version: Version of Maven to execute Sonar with.
+ :mvn-settings: Maven settings.xml file containing credentials to use.
+ :sonarcloud-project-key: SonarCloud project key.
+ :sonarcloud-project-organization: SonarCloud project organization.
+ :sonarcloud-api-token: SonarCloud API Token.
+
lf-maven-build
--------------
:gerrit_release_triggers: Override Gerrit Triggers.
+.. _maven-sonar:
+
Maven Sonar
-----------
:mvn-opts: Sets MAVEN_OPTS. (default: '')
:mvn-params: Additional mvn parameters to pass to the cli. (default: '')
:mvn-version: Version of maven to use. (default: mvn35)
+ :sonar-mvn-goals: Maven goals to run for sonar analysis.
+ (default: sonar:sonar)
+ :sonarcloud: Whether or not to use SonarCloud ``true|false``.
+ (default: false)
+ :sonarcloud-project-key: SonarCloud project key. (default: '')
+ :sonarcloud-project-organization: SonarCloud project organization.
+ (default: '')
+ :sonarcloud-api-token: SonarCloud API Token. (default: '')
:stream: Keyword that can be used to represent a release code-name.
Often the same as the branch. (default: master)
:submodule-recursive: Whether to checkout submodules recursively.
:gerrit_sonar_triggers: Override Gerrit Triggers.
+
+SonarCloud Example:
+
+.. literalinclude:: ../../.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml
+ :language: yaml
+
Maven Verify
------------
mvn-params: ''
mvn-version: mvn35
sonar-mvn-goal: 'sonar:sonar'
+ sonarcloud: false
+ sonarcloud-project-key: ''
+ sonarcloud-project-organization: ''
+ sonarcloud-api-token: ''
stream: master
submodule-recursive: true
submodule-timeout: 10
builders:
- lf-infra-pre-build
- - lf-infra-maven-sonar:
- java-version: '{java-version}'
- mvn-settings: '{mvn-settings}'
- mvn-version: '{mvn-version}'
+ # With SonarCloud
+ - conditional-step:
+ condition-kind: boolean-expression
+ condition-expression: '{sonarcloud}'
+ steps:
+ - shell: echo 'Using SonarCloud'
+ - lf-infra-maven-sonarcloud:
+ java-version: '{java-version}'
+ mvn-settings: '{mvn-settings}'
+ mvn-version: '{mvn-version}'
+ sonarcloud-project-key: '{sonarcloud-project-key}'
+ sonarcloud-project-organization: '{sonarcloud-project-organization}'
+ sonarcloud-api-token: '{sonarcloud-api-token}'
+ # With SonarQube
+ - conditional-step:
+ condition-kind: not
+ condition-operand:
+ condition-kind: boolean-expression
+ condition-expression: '{sonarcloud}'
+ steps:
+ - shell: echo 'Using SonarQube'
+ - lf-infra-maven-sonar:
+ java-version: '{java-version}'
+ mvn-settings: '{mvn-settings}'
+ mvn-version: '{mvn-version}'
publishers:
- lf-jacoco-report
- ../shell/maven-sonar.sh
- lf-provide-maven-settings-cleanup
+- builder:
+ name: lf-infra-maven-sonarcloud
+ # Run a Sonar build with Maven
+ builders:
+ - lf-maven-install:
+ mvn-version: '{mvn-version}'
+ - lf-update-java-alternatives:
+ java-version: '{java-version}'
+ - inject:
+ # Switch this to the sonar wrapper when JJB 2.0 is available
+ properties-content: |
+ SONAR_HOST_URL=https://sonarcloud.io
+ PROJECT_KEY={sonarcloud-project-key}
+ PROJECT_ORGANIZATION={sonarcloud-project-organization}
+ API_TOKEN={sonarcloud-api-token}
+ - lf-provide-maven-settings:
+ global-settings-file: global-settings
+ settings-file: '{mvn-settings}'
+ - shell: !include-raw-escape:
+ - ../shell/common-variables.sh
+ - ../shell/maven-sonar.sh
+ - lf-provide-maven-settings-cleanup
+
- job-template:
name: '{project-name}-sonar'
id: gerrit-maven-sonar
--- /dev/null
+---
+features:
+ - |
+ Add support for pushing Sonar results to SonarCloud. Refer to
+ :ref:`Maven Sonar docs <maven-sonar>` for details.
export MAVEN_OPTS
+declare -a params
+params+=("--global-settings $GLOBAL_SETTINGS_FILE")
+params+=("--settings $SETTINGS_FILE")
+
# Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters.
# shellcheck disable=SC2086
$MVN clean install \
-e -Dsonar \
- --global-settings "$GLOBAL_SETTINGS_FILE" \
- --settings "$SETTINGS_FILE" \
+ ${params[*]} \
$MAVEN_OPTIONS $MAVEN_PARAMS
+if [ "$SONAR_HOST_URL" = "https://sonarcloud.io" ]; then
+ params+=("-Dsonar.projectKey=$PROJECT_KEY")
+ params+=("-Dsonar.organization=$PROJECT_ORGANIZATION")
+ params+=("-Dsonar.login=$API_TOKEN")
+fi
+
# Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters.
# shellcheck disable=SC2086
-$MVN $SONAR_MAVEN_GOAL \
+"$MVN" $SONAR_MAVEN_GOAL \
-e -Dsonar -Dsonar.host.url="$SONAR_HOST_URL" \
- --global-settings "$GLOBAL_SETTINGS_FILE" \
- --settings "$SETTINGS_FILE" \
+ ${params[*]} \
$MAVEN_OPTIONS $MAVEN_PARAMS