From: Lott, Christopher (cl778h) Date: Mon, 10 Feb 2020 20:58:11 +0000 (-0500) Subject: Add support for Sonar pre-scan shell script X-Git-Tag: v0.51.0^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F79%2F63079%2F4;p=releng%2Fglobal-jjb.git Add support for Sonar pre-scan shell script 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) Issue-ID: RELENG-2712 --- diff --git a/.jjb-test/lf-ci-jobs.yaml b/.jjb-test/lf-ci-jobs.yaml index 65a4fab2..f7eed0d0 100644 --- a/.jjb-test/lf-ci-jobs.yaml +++ b/.jjb-test/lf-ci-jobs.yaml @@ -88,3 +88,27 @@ - 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" diff --git a/docs/jjb/lf-ci-jobs.rst b/docs/jjb/lf-ci-jobs.rst index d3f343ed..65568e2d 100644 --- a/docs/jjb/lf-ci-jobs.rst +++ b/docs/jjb/lf-ci-jobs.rst @@ -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: "") diff --git a/jjb/lf-ci-jobs.yaml b/jjb/lf-ci-jobs.yaml index 59045b6b..e4ef0669 100644 --- a/jjb/lf-ci-jobs.yaml +++ b/jjb/lf-ci-jobs.yaml @@ -2054,6 +2054,18 @@ 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: @@ -2154,3 +2166,21 @@ <<: *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 index 00000000..29c1fa56 --- /dev/null +++ b/releasenotes/notes/sonar-prescan-script-3d2122df77d463ea.yaml @@ -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.