From: Houa Yang Date: Thu, 15 Aug 2019 21:40:44 +0000 (-0500) Subject: Add lf-sonar-common job-template X-Git-Tag: v0.42.0~5^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F71%2F16571%2F8;p=releng%2Fglobal-jjb.git Add lf-sonar-common job-template Add lf-sonar-common job-template for sonar-project.properties Issue: RELENG-1304 Signed-off-by: Houa Yang Change-Id: I6788bf9afb3b25fb751b806f08fddcf2fed42d26 --- diff --git a/docs/jjb/lf-ci-jobs.rst b/docs/jjb/lf-ci-jobs.rst index 5c683b1f..1d3e6c10 100644 --- a/docs/jjb/lf-ci-jobs.rst +++ b/docs/jjb/lf-ci-jobs.rst @@ -806,3 +806,22 @@ the base directory is usually the best place to run from. (default: 10) :submodule-disable: Disable submodule checkout operation. (default: false) + + +Sonar +----- + +Runs Jenkins Sonarqube plug-in to review for bugs, code smells, +and security vulnerabilities. + +:Template Names: + + - {project-name}-sonar + - gerrit-sonar + - github-sonar + +:Optional Parameters: + :sonar-task: Sonar task to run. (default: "") + :sonar-properties: Sonar configuration properties. (default: "") + :sonar-java-opts: JVM options. (default: "") + :sonar-additional-args: Additional command line arguments. (default: "") diff --git a/docs/jjb/lf-macros.rst b/docs/jjb/lf-macros.rst index 32aa2be3..9b5773a5 100644 --- a/docs/jjb/lf-macros.rst +++ b/docs/jjb/lf-macros.rst @@ -277,6 +277,17 @@ lf-infra-provide-docker-cleanup Forcibly removes all of the docker images. +lf-infra-sonar +--------------- + +Runs Jenkins Sonar plug-in + +:Optional Parameters: + :sonar-task: Sonar task to run. (default: "") + :sonar-properties: Sonar configuration properties. (default: "") + :sonar-java-opts: JVM options. (default: "") + :sonar-additional-args: Additional command line arguments. (default: "") + Parameters ========== diff --git a/jjb/lf-ci-jobs.yaml b/jjb/lf-ci-jobs.yaml index 4d5dd2e4..f492dd77 100644 --- a/jjb/lf-ci-jobs.yaml +++ b/jjb/lf-ci-jobs.yaml @@ -1834,3 +1834,163 @@ included-regions: "{obj:github_included_regions}" white-list-target-branches: - "{branch}" + +######### +# Sonar # +######### + +- lf_sonar_common: &lf_sonar_common + name: lf-sonar-common + + ###################### + # Default parameters # + ###################### + + archive-artifacts: > + **/*.log + + branch: master # Sonar should always be run on master branch + build-days-to-keep: 7 + build-timeout: 60 + cron: "H H * * *" # run daily + disable-job: false + git-url: "$GIT_URL/$PROJECT" + github-url: "https://github.com" + stream: master + submodule-recursive: true + submodule-timeout: 10 + submodule-disable: false + + # Sonar properties + sonar-task: "" + sonar-properties: "" + sonar-java-opts: "" + sonar-additional-args: "" + + gerrit_trigger_file_paths: + - compare-type: REG_EXP + pattern: ".*" + + # github_included_regions MUST match gerrit_trigger_file_paths + github_included_regions: + - ".*" + + ##################### + # Job Configuration # + ##################### + + project-type: freestyle + node: "{build-node}" + + properties: + - lf-infra-properties: + build-days-to-keep: "{build-days-to-keep}" + + wrappers: + - lf-infra-wrappers: + build-timeout: "{build-timeout}" + jenkins-ssh-credential: "{jenkins-ssh-credential}" + + disabled: "{disable-job}" + + parameters: + - lf-infra-parameters: + project: "{project}" + branch: "{branch}" + stream: "{stream}" + - string: + name: ARCHIVE_ARTIFACTS + default: "{archive-artifacts}" + description: Artifacts to archive to the logs server. + + builders: + - lf-infra-pre-build + - lf-infra-sonar: + sonar-task: "{sonar-task}" + sonar-properties: "{sonar-properties}" + sonar-java-opts: "{sonar-java-opts}" + sonar-additional-args: "{sonar-additional-args}" + + publishers: + - lf-infra-publish + +- job-template: + name: "{project-name}-sonar" + id: gerrit-sonar + <<: *lf_sonar_common + # yamllint disable-line rule:key-duplicates + + ###################### + # Default parameters # + ###################### + + gerrit_sonar_triggers: + - comment-added-contains-event: + comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$' + + ##################### + # Job Configuration # + ##################### + + scm: + - lf-infra-gerrit-scm: + jenkins-ssh-credential: "{jenkins-ssh-credential}" + git-url: "{git-url}" + refspec: $GERRIT_REFSPEC + branch: $GERRIT_BRANCH + submodule-recursive: "{submodule-recursive}" + submodule-timeout: "{submodule-timeout}" + submodule-disable: "{submodule-disable}" + choosing-strategy: default + + triggers: + - timed: "{obj:cron}" + - gerrit: + server-name: "{gerrit-server-name}" + trigger-on: "{obj:gerrit_sonar_triggers}" + projects: + - project-compare-type: "ANT" + project-pattern: "{project}" + branches: + - branch-compare-type: "ANT" + branch-pattern: "**/{branch}" + file-paths: "{obj:gerrit_trigger_file_paths}" + skip-vote: + successful: true + failed: true + unstable: true + notbuilt: true + +- job-template: + name: "{project-name}-sonar" + id: github-sonar + <<: *lf_sonar_common + # yamllint disable-line rule:key-duplicates + + properties: + - lf-infra-properties: + build-days-to-keep: "{build-days-to-keep}" + - github: + url: "{github-url}/{github-org}/{project}" + + scm: + - lf-infra-github-scm: + url: "{git-clone-url}{github-org}/{project}" + refspec: "+refs/pull/*:refs/remotes/origin/pr/*" + branch: "$sha1" + submodule-recursive: "{submodule-recursive}" + submodule-timeout: "{submodule-timeout}" + submodule-disable: "{submodule-disable}" + choosing-strategy: default + jenkins-ssh-credential: "{jenkins-ssh-credential}" + + triggers: + - github-pull-request: + trigger-phrase: "^run-sonar$" + only-trigger-phrase: false + status-context: "Python Sonar" + permit-all: true + github-hooks: true + white-list-target-branches: + - "{branch}" + included-regions: "{obj:github_included_regions}" diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index ca7d478d..24c77bee 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -316,6 +316,19 @@ docker rmi -f $(docker images -a -q) exit 0 +- builder: + name: lf-infra-sonar + # Run a Sonar Jenkins Plugin + builders: + - sonar: + sonar-name: Sonar + scanner-name: SonarQubeScanner + task: "{sonar-task}" + project: "sonar-project.properties" + properties: "{sonar-properties}" + java-opts: "{sonar-java-opts}" + additional-arguments: "{sonar-additional-args}" + ############## # PARAMETERS # ############## diff --git a/releasenotes/notes/lf-sonar-common-job-template-f9755d687c79b462.yaml b/releasenotes/notes/lf-sonar-common-job-template-f9755d687c79b462.yaml new file mode 100644 index 00000000..b449159e --- /dev/null +++ b/releasenotes/notes/lf-sonar-common-job-template-f9755d687c79b462.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Add lf-sonar-common job-template to lf-ci-jobs.yaml and add lf-infra-sonar + to macros.yaml. The purpose of a new job template is to adopt using jenkins + sonar plug-in along with the sonar-project.properties file versus pom.xml. + Lastly the new job template will ensure that anything using lf-infra-tox-sonar + is unaffected.