- project-view
project-name: ci-jobs
+
+# required by gerrit-sonar-prescan and github-sonar-prescan
+- builder:
+ name: lf-sonar-prescan
+ builders:
+ - shell: "#!/bin/sh"
+
+- project:
+ name: gerrit-sonar-jobs
+ project-name: gerrit-ciman
+ jobs:
+ - gerrit-sonar
+ - gerrit-sonar-prescan
+ - gerrit-sonar-prescan-script:
+ sonar-prescan-script: "#!/bin/sh"
+
+- project:
+ name: github-sonar-jobs
+ project-name: github-ciman
+ jobs:
+ - github-sonar
+ - github-sonar-prescan
+ - github-sonar-prescan-script:
+ sonar-prescan-script: "#!/bin/sh"
Sonar
-----
-Runs Jenkins Sonarqube plug-in to review for bugs, code smells,
-and security vulnerabilities.
+Runs the Jenkins SonarQube Scanner plug-in to analyze code for bugs,
+code smells and security vulnerabilities, and to upload the result
+(possibly including code-coverage statistics) to a SonarQube server
+or to SonarCloud.io.
Requires ``SonarQube Scanner for Jenkins``
+One of the optional parameters sonar-project-file and sonar-properties
+must be supplied; they cannot both be empty.
+
Plug-in configurations
Manage Jenkins --> Configure System --> SonarQube servers
- Name: Sonar (fixed)
:sonar-properties: Sonar configuration properties. (default: "")
:sonar-java-opts: JVM options. (default: "")
:sonar-additional-args: Additional command line arguments. (default: "")
+
+
+Sonar with Prescan Script
+-------------------------
+
+The same as the Sonar job above, except the caller must supply a shell script
+to run prior to the Sonar scan. This is commonly used to install prerequisites,
+build the project, execute unit tests and generate a code-coverage report.
+
+:Template Names:
+
+ - {project-name}-sonar-prescan-script
+ - gerrit-sonar-prescan-script
+ - github-sonar-prescan-script
+
+:Required Parameters:
+ :sonar-prescan-script: A shell script that will run prior to the Sonar scan.
+
+:Optional Parameters:
+ :sonar-task: Sonar task to run. (default: "")
+ :sonar-project-file: The filename for the project's properties.
+ (default: "sonar-project.properties")
+ :sonar-properties: Sonar configuration properties. (default: "")
+ :sonar-java-opts: JVM options. (default: "")
+ :sonar-additional-args: Additional command line arguments. (default: "")
sonar-java-opts: "{sonar-java-opts}"
sonar-additional-args: "{sonar-additional-args}"
+- lf_sonar_builders_prescan_script: &lf_sonar_builders_prescan_script
+ name: lf-sonar-builders-prescan-script
+ builders:
+ - lf-infra-pre-build
+ - shell: "{sonar-prescan-script}"
+ - lf-infra-sonar:
+ sonar-task: "{sonar-task}"
+ sonar-project-file: "{sonar-project-file}"
+ sonar-properties: "{sonar-properties}"
+ sonar-java-opts: "{sonar-java-opts}"
+ sonar-additional-args: "{sonar-additional-args}"
+
- lf_sonar_gerrit_common: &lf_sonar_gerrit_common
name: lf-sonar-gerrit-common
gerrit_sonar_triggers:
<<: *lf_sonar_builders_prescan
# yamllint disable-line rule:key-duplicates
<<: *lf_sonar_github_common
+
+- job-template:
+ name: "{project-name}-sonar-prescan-script"
+ id: gerrit-sonar-prescan-script
+ <<: *lf_sonar_common
+ # yamllint disable-line rule:key-duplicates
+ <<: *lf_sonar_builders_prescan_script
+ # yamllint disable-line rule:key-duplicates
+ <<: *lf_sonar_gerrit_common
+
+- job-template:
+ name: "{project-name}-sonar-prescan-script"
+ id: github-sonar-prescan-script
+ <<: *lf_sonar_common
+ # yamllint disable-line rule:key-duplicates
+ <<: *lf_sonar_builders_prescan_script
+ # yamllint disable-line rule:key-duplicates
+ <<: *lf_sonar_github_common
--- /dev/null
+---
+features:
+ - |
+ New templates gerrit-sonar-prescan-script and github-sonar-prescan-script
+ accept an arbitrary shell-script body that can do work like install
+ prerequisites, build and test to generate a code-coverage report for
+ the Sonar Scanner to find and upload. This adds flexibility that the
+ existing gerrit-sonar-prescan and github-sonar-prescan templates lack.