Sonar scans for Python based repos. This job invokes tox to run tests
and gather coverage statistics from the test results, then invokes
-Maven to publish the results to a Sonar server.
+Maven to publish the results to either a Sonar server or SonarCloud.
To get the Sonar coverage results, file tox.ini must exist and contain
coverage commands to run.
suites. Checking coverage does not guarantee that the tests execute
properly, but it identifies code that is not executed by any test.
-This job reuses the Sonar builder used in Java/Maven projects which
-runs maven twice. The first invocation does nothing for Python
+This job reuses the Sonar builders used for Java/Maven projects which
+run maven twice. The first invocation does nothing for Python
projects, so the job uses the goal 'validate' by default. The second
invocation publishes results using the goal 'sonar:sonar' by default.
(default: a string with a shell comment)
:python-version: Python version to invoke pip install of tox-pyenv
(default: python2)
+ :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: '')
:sonar-mvn-goal: The Maven goal to run the Sonar plugin. (default: sonar:sonar)
:stream: Keyword used to represent a release code-name.
Often the same as the branch. (default: master)
(default: 10)
:submodule-disable: Disable submodule checkout operation.
(default: false)
+ :tox-dir: Directory containing the project's tox.ini relative to
+ the workspace. The default uses tox.ini at the project root.
+ (default: '.')
+ :tox-envs: Tox environments to run. If blank run everything described
+ in tox.ini. (default: '')
:gerrit_sonar_triggers: Override Gerrit Triggers.
:gerrit_trigger_file_paths: Override file paths used to filter which file
modifications trigger a build. Refer to JJB documentation for "file-path" details.
pre-build-script: "# pre-build script goes here"
python-version: python3
sonar-mvn-goal: "sonar:sonar"
+ sonarcloud: false
+ sonarcloud-project-key: ""
+ sonarcloud-project-organization: ""
+ sonarcloud-api-token: ""
stream: master
submodule-recursive: true
submodule-timeout: 10
submodule-disable: false
+ tox-dir: "."
+ tox-envs: ""
gerrit_trigger_file_paths:
- compare-type: REG_EXP
project: "{project}"
branch: "{branch}"
stream: "{stream}"
+ - lf-infra-tox-parameters:
+ tox-dir: "{tox-dir}"
+ tox-envs: "{tox-envs}"
- string:
name: ARCHIVE_ARTIFACTS
default: "{archive-artifacts}"
- lf-provide-maven-settings:
global-settings-file: "{mvn-global-settings}"
settings-file: "{mvn-settings}"
- - lf-infra-maven-sonar:
- java-version: "{java-version}"
- mvn-goals: "{mvn-goals}"
- 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-goals: "{mvn-goals}"
+ 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-goals: "{mvn-goals}"
+ mvn-settings: "{mvn-settings}"
+ mvn-version: "{mvn-version}"
publishers:
- lf-infra-publish
--- /dev/null
+---
+upgrade:
+ - |
+ Extend lf_tox_sonar with sonarcloud, sonarcloud-project-key,
+ sonarcloud-project-organization, sonarcloud-api-token, tox-dir
+ and tox-envs properties; also with lf-infra-tox-parameters macro.
+ Use new sonarcloud property as guard for conditional builder step,
+ if true use lf-infra-maven-sonarcloud, else use lf-infra-maven-sonar.