---
# verification jobs for 'osam' repo

- project:
    name: osam
    project: '{name}'

    jobs:
      - 'verify-osam-jobs':
          branch-regexp: '{supported-branches-regexp}'

- job-group:
    name: 'verify-osam-jobs'
    jobs:
      - 'verify-licensed'
      - 'osam-test':
          dependency-jobs: 'verify_osam_licensed'

- job-template:
    id: 'osam-test'
    name: 'verify_{project}_test'

    description: |
      Created by {id} job-template from ci-management/jjb/verify/osam.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: '{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: 40
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - cord-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}'
          basedir: '{basedir}'

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

    builders:
      # NOTE: this env var is only required to fix a bug in the "surefire" dependency:
      #  https://issues.apache.org/jira/browse/SUREFIRE-1588
      #  https://github.com/apache/maven-surefire/pull/197
      #  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911925
      # should be removed as soon as this problem is resolved
      - inject:
          properties-content: |
            _JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true

      - shell: |
          #!/usr/bin/env bash
          set -eux -o pipefail

          echo "Starting database for OSAM tests"

          # pull database
          docker pull mariadb:10.3-bionic

          # run database
          # Settings for the following commmand must match values given
          # in: osam-core/model/src/main/resources/application.properties

          docker run -d -p 3306:3306 --name springbootdb \
                     -e MYSQL_DATABASE=osam_core \
                     -e MYSQL_USER=root \
                     -e MYSQL_ROOT_PASSWORD=123456 \
                     mariadb:10.3-bionic

          # wait for mariadb to start up, print docker container status
          sleep 15
          docker ps -a

      - maven-target:
          goals: "test"
          pom: "pom.xml"

    publishers:
      - postbuildscript:
          builders:
            - build-on:
                - SUCCESS
                - UNSTABLE
                - FAILURE
              build-steps:
                - shell: |
                    #!/usr/bin/env bash
                    set -eux -o pipefail

                    echo "Stopping database"
                    docker ps -a
                    docker rm -f springbootdb

