---
# Sonarqube coverage tests
#
# There are two kinds of tests:
#
#  - coverage_{project}_sonarqube - run after merge to give an idea of ongoing code health
#  - verify_{project}_sonarqube - run on patchsets, invoked in the verify/*.yaml
#
# JJB module docs:
#  https://docs.openstack.org/infra/jenkins-job-builder/builders.html?highlight=sonar#builders.sonar
#
# Sonarqube docs:
#  https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins
#  https://docs.sonarqube.org/display/SCAN/Advanced+SonarQube+Scanner+Usages
#
# Variables:
#  sonar-java-binaries - paths to Java bytecodefiles for SonarQube to analyze. Defaults to "".
#                        See: https://docs.sonarqube.org/display/PLUG/Java+Plugin+and+Bytecode
#  sonar-prep-commands - shell commands to run before SonarScanner is run, frequently used to
#                        build java bytecode. Defaults to "" (nothing run)
#

- project:
    name: 'sonarqube-ongoing-coverage'

    jobs:
      - 'sonarqube-coverage':
          branch-regexp: '{supported-branches-regexp}'
          project:
            - 'cord'
            - 'ecord'
            - 'maas'
            - 'mcord'
            - 'platform-install'
            - 'rcord'
            - 'xos'
            - 'xos-gui'

# run ongoing coverage tests on merged patchsets
- job-template:
    id: sonarqube-coverage
    name: 'coverage_{project}_sonarqube'
    description: |
      Created by sonarqube-coverage job-template from ci-management/jjb/sonar.yaml

    triggers:
      - cord-infra-gerrit-trigger-merge:
          gerrit-server-name: '{gerrit-server-name}'
          project-regexp: '^{project}$'
          branch-regexp: '{branch-regexp}'
          dependency-jobs: '{dependency-jobs}'
          file-include-regexp: '{all-files-regexp}'

    properties:
      - cord-infra-properties:
          build-days-to-keep: '{build-days-to-keep}'
          artifact-num-to-keep: '{artifact-num-to-keep}'

    wrappers:
      - lf-infra-wrappers:
          build-timeout: '{build-timeout}'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - lf-infra-gerrit-scm:
          git-url: '$GIT_URL/$GERRIT_PROJECT'
          refspec: ''
          branch: '$GERRIT_BRANCH'
          submodule-recursive: 'false'
          choosing-strategy: 'gerrit'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    node: 'ubuntu16.04-basebuild-1c-2g'
    project-type: freestyle
    concurrent: true

    builders:
        - 'cord-infra-sonarqube':
            project: '{project}'
            sonar-prep-commands: '{sonar-prep-commands}'
            sonar-java-binaries: '{sonar-java-binaries}'

# run Sonarqube as a verification jobs on individual patchsets
- job-template:
    id: verify-sonarqube
    name: 'verify_{project}_sonarqube'
    description: |
      Created by verify-sonarqube job-template from ci-management/jjb/sonar.yaml

    triggers:
      - cord-infra-gerrit-trigger-patchset:
          gerrit-server-name: '{gerrit-server-name}'
          project-regexp: '^{project}$'
          branch-regexp: '{branch-regexp}'
          dependency-jobs: '{dependency-jobs}'
          file-include-regexp: '{code-files-regexp}'

    properties:
      - cord-infra-properties:
          build-days-to-keep: '{build-days-to-keep}'
          artifact-num-to-keep: '{artifact-num-to-keep}'

    wrappers:
      - lf-infra-wrappers:
          build-timeout: '{build-timeout}'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - lf-infra-gerrit-scm:
          git-url: '$GIT_URL/$GERRIT_PROJECT'
          refspec: '$GERRIT_REFSPEC'
          branch: '$GERRIT_BRANCH'
          submodule-recursive: 'false'
          choosing-strategy: gerrit
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    node: 'ubuntu16.04-basebuild-1c-2g'
    project-type: freestyle
    concurrent: true

    builders:
        - 'cord-infra-sonarqube':
            project: '{project}'
            sonar-prep-commands: '{sonar-prep-commands}'
            sonar-java-binaries: '{sonar-java-binaries}'
