Add support for Sonar pre-scan shell script 79/63079/4
authorLott, Christopher (cl778h) <cl778h@att.com>
Mon, 10 Feb 2020 20:58:11 +0000 (15:58 -0500)
committerLott, Christopher (cl778h) <cl778h@att.com>
Tue, 11 Feb 2020 01:42:37 +0000 (20:42 -0500)
New templates gerrit-sonar-prescan-script, github-sonar-prescan-script
accept an arbitrary shell-script body that can install prerequisites,
build and test to generate a code-coverage report for the Sonar Scanner
to find and upload.  This lifts limitations in existing templates
gerrit-sonar-prescan, github-sonar-prescan.

Change-Id: Ie61a5bed99a21fd62cb74f89d3e153ab0c3a4108
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
Issue-ID: RELENG-2712

.jjb-test/lf-ci-jobs.yaml
docs/jjb/lf-ci-jobs.rst
jjb/lf-ci-jobs.yaml
releasenotes/notes/sonar-prescan-script-3d2122df77d463ea.yaml [new file with mode: 0644]

index 65a4fab..f7eed0d 100644 (file)
       - 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"
index d3f343e..65568e2 100644 (file)
@@ -880,11 +880,16 @@ the base directory is usually the best place to run from.
 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)
@@ -946,3 +951,28 @@ to run prior to the Sonar scan.
     :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: "")
index 59045b6..e4ef066 100644 (file)
           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
diff --git a/releasenotes/notes/sonar-prescan-script-3d2122df77d463ea.yaml b/releasenotes/notes/sonar-prescan-script-3d2122df77d463ea.yaml
new file mode 100644 (file)
index 0000000..29c1fa5
--- /dev/null
@@ -0,0 +1,8 @@
+---
+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.