Merge "Support sonarcloud in python projects"
authorAnil Belur <abelur@linuxfoundation.org>
Wed, 16 Oct 2019 13:49:44 +0000 (13:49 +0000)
committerGerrit Code Review <gerrit@linuxfoundation.org>
Wed, 16 Oct 2019 13:49:44 +0000 (13:49 +0000)
1  2 
docs/jjb/lf-python-jobs.rst
jjb/lf-python-jobs.yaml

@@@ -128,7 -128,7 +128,7 @@@ Python Sonar with To
  
  Sonar scans for Python based repos. This job invokes tox to run tests
  and gather coverage statistics from the test results, then invokes
- Maven to publish the results to a Sonar server.
+ Maven to publish the results to either a Sonar server or SonarCloud.
  
  To get the Sonar coverage results, file tox.ini must exist and contain
  coverage commands to run.
@@@ -137,8 -137,8 +137,8 @@@ The coverage commands define the code t
  suites.  Checking coverage does not guarantee that the tests execute
  properly, but it identifies code that is not executed by any test.
  
- This job reuses the Sonar builder used in Java/Maven projects which
- runs maven twice. The first invocation does nothing for Python
+ This job reuses the Sonar builders used for Java/Maven projects which
+ run maven twice. The first invocation does nothing for Python
  projects, so the job uses the goal 'validate' by default. The second
  invocation publishes results using the goal 'sonar:sonar' by default.
  
@@@ -196,6 -196,12 +196,12 @@@ https://docs.sonarqube.org/display/PLUG
          (default: a string with a shell comment)
      :python-version: Python version to invoke pip install of tox-pyenv
          (default: python2)
+     :sonarcloud: Whether or not to use SonarCloud ``true|false``.
+         (default: false)
+     :sonarcloud-project-key: SonarCloud project key. (default: '')
+     :sonarcloud-project-organization: SonarCloud project organization.
+         (default: '')
+     :sonarcloud-api-token: SonarCloud API Token. (default: '')
      :sonar-mvn-goal: The Maven goal to run the Sonar plugin. (default: sonar:sonar)
      :stream: Keyword used to represent a release code-name.
          Often the same as the branch. (default: master)
          (default: 10)
      :submodule-disable: Disable submodule checkout operation.
          (default: false)
+     :tox-dir: Directory containing the project's tox.ini relative to
+         the workspace. The default uses tox.ini at the project root.
+         (default: '.')
+     :tox-envs: Tox environments to run. If blank run everything described
+         in tox.ini. (default: '')
      :gerrit_sonar_triggers: Override Gerrit Triggers.
      :gerrit_trigger_file_paths: Override file paths used to filter which file
          modifications trigger a build. Refer to JJB documentation for "file-path" details.
@@@ -438,7 -449,7 +449,7 @@@ PyPI section
      - gerrit-pypi-merge
      - github-pypi-merge
  
 -:Comment Trigger: pypi-remerge
 +:Comment Trigger: remerge
  
  :Required Parameters:
  
@@@ -552,8 -563,6 +563,8 @@@ An example of a pypi release file appea
      - gerrit-pypi-release-verify
      - github-pypi-release-verify
  
 +:Comment Trigger: recheck
 +
  :Required Parameters:
  
      :build-node: The node to run build on, which must be Centos.
@@@ -635,8 -644,6 +646,8 @@@ The special parameters are as follows:
      - gerrit-pypi-release-merge
      - github-pypi-release-merge
  
 +:Comment Trigger: remerge
 +
  :Required Parameters:
  
      :build-node: The node to run build on, which must be Centos.
diff --combined jjb/lf-python-jobs.yaml
      pre-build-script: "# pre-build script goes here"
      python-version: python3
      sonar-mvn-goal: "sonar:sonar"
+     sonarcloud: false
+     sonarcloud-project-key: ""
+     sonarcloud-project-organization: ""
+     sonarcloud-api-token: ""
      stream: master
      submodule-recursive: true
      submodule-timeout: 10
      submodule-disable: false
+     tox-dir: "."
+     tox-envs: ""
  
      gerrit_trigger_file_paths:
        - compare-type: REG_EXP
            project: "{project}"
            branch: "{branch}"
            stream: "{stream}"
+       - lf-infra-tox-parameters:
+           tox-dir: "{tox-dir}"
+           tox-envs: "{tox-envs}"
        - string:
            name: ARCHIVE_ARTIFACTS
            default: "{archive-artifacts}"
        - lf-provide-maven-settings:
            global-settings-file: "{mvn-global-settings}"
            settings-file: "{mvn-settings}"
-       - lf-infra-maven-sonar:
-           java-version: "{java-version}"
-           mvn-goals: "{mvn-goals}"
-           mvn-settings: "{mvn-settings}"
-           mvn-version: "{mvn-version}"
+       # With SonarCloud
+       - conditional-step:
+           condition-kind: boolean-expression
+           condition-expression: "{sonarcloud}"
+           steps:
+             - shell: echo 'Using SonarCloud'
+             - lf-infra-maven-sonarcloud:
+                 java-version: "{java-version}"
+                 mvn-goals: "{mvn-goals}"
+                 mvn-settings: "{mvn-settings}"
+                 mvn-version: "{mvn-version}"
+                 sonarcloud-project-key: "{sonarcloud-project-key}"
+                 sonarcloud-project-organization: "{sonarcloud-project-organization}"
+                 sonarcloud-api-token: "{sonarcloud-api-token}"
+       # With SonarQube
+       - conditional-step:
+           condition-kind: not
+           condition-operand:
+             condition-kind: boolean-expression
+             condition-expression: "{sonarcloud}"
+           steps:
+             - shell: echo 'Using SonarQube'
+             - lf-infra-maven-sonar:
+                 java-version: "{java-version}"
+                 mvn-goals: "{mvn-goals}"
+                 mvn-settings: "{mvn-settings}"
+                 mvn-version: "{mvn-version}"
  
      publishers:
        - lf-infra-publish
      pre-build-script: "# pre-build script goes here"
      python-version: python3
      stream: master
 +    submodule-disable: false
      submodule-recursive: true
      submodule-timeout: 10
 -    submodule-disable: false
      tox-dir: "."
      tox-envs: ""
  
      <<: *lf_pypi_common
      <<: *lf_pypi_verify_builders
  
 -    gerrit_verify_triggers:
 -      - patchset-created-event:
 -          exclude-drafts: true
 -          exclude-trivial-rebase: false
 -          exclude-no-code-change: false
 -      - draft-published-event
 -      - comment-added-contains-event:
 -          comment-contains-value: '^Patch Set\s+\d+:\s+(recheck|reverify)\s*$'
 -
      scm:
        - lf-infra-gerrit-scm:
            jenkins-ssh-credential: "{jenkins-ssh-credential}"
      triggers:
        - gerrit:
            server-name: "{gerrit-server-name}"
 -          trigger-on: "{obj:gerrit_verify_triggers}"
 +          trigger-on:
 +            - patchset-created-event:
 +                exclude-drafts: true
 +                exclude-trivial-rebase: false
 +                exclude-no-code-change: false
 +            - draft-published-event
 +            - comment-added-contains-event:
 +                comment-contains-value: '^Patch Set\s+\d+:\s+(recheck|reverify)\s*$'
            projects:
              - project-compare-type: ANT
                project-pattern: "{project}"
      cron: ""
      pypi-repo: pypi-test
  
 -    gerrit_merge_triggers:
 -      - change-merged-event
 -      - comment-added-contains-event:
 -          comment-contains-value: '^Patch Set\s+\d+:\s+remerge\s*$'
 -
      scm:
        - lf-infra-gerrit-scm:
            jenkins-ssh-credential: "{jenkins-ssh-credential}"
        - timed: "{obj:cron}"
        - gerrit:
            server-name: "{gerrit-server-name}"
 -          trigger-on: "{obj:gerrit_merge_triggers}"
 +          trigger-on:
 +            - change-merged-event
 +            - comment-added-contains-event:
 +                comment-contains-value: '^Patch Set\s+\d+:\s+remerge\s*$'
            projects:
              - project-compare-type: ANT
                project-pattern: "{project}"
      <<: *lf_pypi_release_common
      <<: *lf_pypi_release_verify_builders
  
 -    gerrit_verify_triggers:
 -      - patchset-created-event:
 -          exclude-drafts: true
 -          exclude-trivial-rebase: false
 -          exclude-no-code-change: false
 -      - draft-published-event
 -      - comment-added-contains-event:
 -          comment-contains-value: '^Patch Set\s+\d+:\s+(recheck|reverify)\s*$'
 -
      scm:
        - lf-infra-gerrit-scm:
            jenkins-ssh-credential: "{jenkins-ssh-credential}"
      triggers:
        - gerrit:
            server-name: "{gerrit-server-name}"
 -          trigger-on: "{obj:gerrit_verify_triggers}"
 +          trigger-on:
 +            - patchset-created-event:
 +                exclude-drafts: true
 +                exclude-trivial-rebase: false
 +                exclude-no-code-change: false
 +            - draft-published-event
 +            - comment-added-contains-event:
 +                comment-contains-value: '^Patch Set\s+\d+:\s+(recheck|reverify)\s*$'
            projects:
              - project-compare-type: "ANT"
                project-pattern: "{project}"
      <<: *lf_pypi_release_common
      <<: *lf_pypi_release_merge_builders
  
 -    gerrit_release_triggers:
 -      - change-merged-event
 -
      scm:
        - lf-infra-gerrit-scm:
            jenkins-ssh-credential: "{jenkins-ssh-credential}"
      triggers:
        - gerrit:
            server-name: "{gerrit-server-name}"
 -          trigger-on: "{obj:gerrit_release_triggers}"
 +          trigger-on:
 +            - change-merged-event
 +            - comment-added-contains-event:
 +                comment-contains-value: '^Patch Set\s+\d+:\s+remerge\s*$'
            projects:
              - project-compare-type: "ANT"
                project-pattern: "{project}"