# Copyright (c) 2020 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- project:
    name: csit
    description: 'CSIT Jenkins jobs.'

    jobs:
      - 'csit-docs-merge-{stream}'
      - 'csit-report-merge-{stream}'
      - 'csit-trending-daily-master'

    project: 'csit'
    branch: 'master'
    executor: 'ubuntu1804-us'
    executor-large: 'ubuntu1804-l'
    build-artifact-num-to-keep: 10
    stream:
      - master:
          branch: 'master'
      - '1908_2':
          branch: 'rls1908_2'
      - '2001':
          branch: 'rls2001'

- project:
    name: csit-view
    views:
      - project-view
    project-name: csit

- job-template:
    name: 'csit-docs-merge-{stream}'

    project-type: freestyle
    node: '{executor}'
    concurrent: true
    allow-empty: 'true'
    fingerprint: false
    only-if-success: true
    default-excludes: false

    build-discarder:
      daysToKeep: '{build-days-to-keep}'
      numToKeep: '{build-num-to-keep}'
      artifactDaysToKeep: '{build-artifact-days-to-keep}'
      artifactNumToKeep: '{build-artifact-num-to-keep}'

    parameters:
      - project-parameter:
          project: '{project}'
      - gerrit-parameter:
          branch: '{branch}'
      - maven-exec:
          maven-version: 'mvn33-new'
      - string:
          name: ARCHIVE_ARTIFACTS
          default: '{archive-artifacts}'
          description: Artifacts to archive to the logs server.

    scm:
      - gerrit-trigger-scm:
          credentials-id: 'jenkins-gerrit-credentials'
          refspec: ''
          choosing-strategy: 'default'

    wrappers:
      - fdio-infra-wrappers-non-activity-timeout:
          build-timeout: '{build-timeout}'

    triggers:
      - reverse:
          jobs: 'csit-vpp-device-{stream}-ubuntu1804-1n-skx-weekly'
          result: 'success'
      - gerrit:
          server-name: 'Primary'
          trigger-on:
            - comment-added-contains-event:
                comment-contains-value: 'run-docs'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: '{project}'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
          skip-vote:
            successful: true
            failed: true
            unstable: true
            notbuilt: true

    builders:
      - maven-target:
          maven-version: 'mvn33-new'
          goals: '--version'
          settings: 'csit-settings'
          settings-type: cfp
          global-settings: 'global-settings'
          global-settings-type: cfp
      - provide-maven-settings:
          settings-file: 'csit-settings'
          global-settings-file: 'global-settings'
      - shell:
          !include-raw-escape:
          - ../scripts/csit/docs.sh

    publishers:
      - fdio-infra-shiplogs:
          maven-version: 'mvn33-new'

- job-template:
    name: 'csit-report-merge-{stream}'

    project-type: freestyle
    node: '{executor-large}'
    concurrent: false
    allow-empty: 'true'
    fingerprint: false
    only-if-success: true
    default-excludes: false

    build-discarder:
      daysToKeep: '{build-days-to-keep}'
      numToKeep: '{build-num-to-keep}'
      artifactDaysToKeep: '{build-artifact-days-to-keep}'
      artifactNumToKeep: '{build-artifact-num-to-keep}'

    parameters:
      - project-parameter:
          project: '{project}'
      - gerrit-parameter:
          branch: '{branch}'
      - maven-exec:
          maven-version: 'mvn33-new'
      - string:
          name: ARCHIVE_ARTIFACTS
          default: '{archive-artifacts}'
          description: Artifacts to archive to the logs server.

    scm:
      - gerrit-trigger-scm:
          credentials-id: 'jenkins-gerrit-credentials'
          refspec: '$GERRIT_REFSPEC'
          choosing-strategy: 'default'

    wrappers:
      - fdio-infra-wrappers-non-activity-timeout:
          build-timeout: '{build-timeout}'

    triggers:
      - gerrit:
          server-name: 'Primary'
          trigger-on:
            - comment-added-contains-event:
                comment-contains-value: 'run-report'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: '{project}'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
          skip-vote:
            successful: true
            failed: true
            unstable: true
            notbuilt: true

    builders:
      - maven-target:
          maven-version: 'mvn33-new'
          goals: '--version'
          settings: 'csit-settings'
          settings-type: cfp
          global-settings: 'global-settings'
          global-settings-type: cfp
      - provide-maven-settings:
          settings-file: 'csit-settings'
          global-settings-file: 'global-settings'
      - shell:
          !include-raw-escape:
          - ../scripts/csit/report.sh

    publishers:
      - fdio-infra-shiplogs:
          maven-version: 'mvn33-new'

- job-template:
    name: 'csit-trending-daily-master'

    project-type: freestyle
    node: '{executor-large}'
    concurrent: false

    build-discarder:
      daysToKeep: '{build-days-to-keep}'
      numToKeep: '{build-num-to-keep}'
      artifactDaysToKeep: '{build-artifact-days-to-keep}'
      artifactNumToKeep: '{build-artifact-num-to-keep}'

    parameters:
      - project-parameter:
          project: '{project}'
      - gerrit-parameter:
          branch: '{branch}'
      - maven-exec:
          maven-version: 'mvn33-new'

    scm:
      - gerrit-trigger-scm:
          credentials-id: 'jenkins-gerrit-credentials'
          refspec: ''
          choosing-strategy: 'default'

    wrappers:
      - fdio-infra-wrappers-non-activity-timeout:
          build-timeout: '{build-timeout}'

    triggers:
      - timed: '0 2,14 * * *'

    builders:
      - maven-target:
          maven-version: 'mvn33-new'
          goals: '--version'
          settings: 'csit-settings'
          settings-type: cfp
          global-settings: 'global-settings'
          global-settings-type: cfp
      - provide-maven-settings:
          settings-file: 'csit-settings'
          global-settings-file: 'global-settings'
      - shell:
          !include-raw-escape:
          - ../scripts/csit/cpta.sh

    publishers:
      - email-ext:
          # yamllint disable-line rule:line-length
          recipients: 'tifrank@cisco.com, csit-report+int+616+181919729795594561@lists.fd.io'
          reply-to: ''
          content-type: 'text'
          subject: 'Failed tests as of  $BUILD_TIMESTAMP'
          # yamllint disable-line rule:line-length
          body: |
                Following tests failed in the last trending job runs, listed per testbed type.

                ${{FILE,path="build-root/docs/deploy-site/src/site/resources/trending/_static/vpp/trending-failed-tests.txt"}}

          always: true
          failure: false

      - email-ext:
          # yamllint disable-line rule:line-length
          recipients: 'tifrank@cisco.com, csit-report+int+616+181919729795594561@lists.fd.io'
          reply-to: ''
          content-type: 'text'
          subject: 'Regressions as of  $BUILD_TIMESTAMP'
          # yamllint disable-line rule:line-length
          body: |
                Following regressions occured in the last trending job runs, listed per testbed type.

                ${{FILE,path="build-root/docs/deploy-site/src/site/resources/trending/_static/vpp/trending-regressions.txt"}}

          always: true
          failure: false

      - email-ext:
          # yamllint disable-line rule:line-length
          recipients: 'tifrank@cisco.com, csit-report+int+616+181919729795594561@lists.fd.io'
          reply-to: ''
          content-type: 'text'
          subject: 'Progressions as of  $BUILD_TIMESTAMP'
          # yamllint disable-line rule:line-length
          body: |
                Following progressions occured in the last trending job runs, listed per testbed type.

                ${{FILE,path="build-root/docs/deploy-site/src/site/resources/trending/_static/vpp/trending-progressions.txt"}}

          always: true
          failure: false

      - fdio-infra-shiplogs:
          maven-version: 'mvn33-new'

- project:
    name: csit-info
    project-name: csit
    jobs:
      - gerrit-info-yaml-verify
    build-node: centos7-builder-4c-4g
    project: csit
    branch: master

- project:
    name: csit-sonar
    project: csit
    project-name: csit
    mvn-settings: csit-settings
    sonarcloud: true
    sonarcloud-project-organization: '{sonarcloud_project_organization}'
    sonarcloud-api-token: '{sonarcloud_api_token}'
    sonarcloud-project-key: '{sonarcloud_project_organization}_{project-name}'
    branch: master
    build-node: centos7-builder-4c-4g
    jobs:
      - gerrit-maven-sonar