Add lf-sonar-common job-template 71/16571/8
authorHoua Yang <hyang@contractor.linuxfoundation.org>
Thu, 15 Aug 2019 21:40:44 +0000 (16:40 -0500)
committerHoua Yang <hyang@contractor.linuxfoundation.org>
Fri, 23 Aug 2019 15:29:47 +0000 (10:29 -0500)
Add lf-sonar-common job-template for sonar-project.properties

Issue: RELENG-1304

Signed-off-by: Houa Yang <hyang@contractor.linuxfoundation.org>
Change-Id: I6788bf9afb3b25fb751b806f08fddcf2fed42d26

docs/jjb/lf-ci-jobs.rst
docs/jjb/lf-macros.rst
jjb/lf-ci-jobs.yaml
jjb/lf-macros.yaml
releasenotes/notes/lf-sonar-common-job-template-f9755d687c79b462.yaml [new file with mode: 0644]

index 5c683b1..1d3e6c1 100644 (file)
@@ -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: "")
index 32aa2be..9b5773a 100644 (file)
@@ -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
 ==========
 
index 4d5dd2e..f492dd7 100644 (file)
           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}"
index ca7d478..24c77be 100644 (file)
           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 (file)
index 0000000..b449159
--- /dev/null
@@ -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.