---
# All job in here builds the binaries
# which will be used by the runner jobs
#
- project:
    name: osmo-gsm-tester-builder

    repo:
      - osmo-bsc
      - osmo-bts
      - osmo-ggsn
      - osmo-hlr
      - osmo-mgw
      - osmo-hnbgw
      - osmo-msc
      - osmo-pcu
      - osmo-sgsn
      - osmo-trx
      - osmocom-bb
      - osmo-stp:
          triggered-by: master-libosmo-sigtran
      - osmo-bts-sysmo:
          triggered-by: master-osmo-bts
      - osmo-pcu-sysmo:
          triggered-by: master-osmo-pcu
      - osmo-bts-oc2g:
          triggered-by: master-osmo-bts
      - osmo-pcu-oc2g:
          triggered-by: master-osmo-pcu
      - open5gs
      - srslte
    triggered-by: 'master-{repo}'

    jobs:
      - 'osmo-gsm-tester_build-{repo}'

- parameter:
    name: add_param_build_branch
    parameters:
      - string:
          name: "{name}"
          default: ""
          description: "Default: leave empty. Branch to build from, in the form my/branch or origin/my/branch (do not prepend 'refs/heads/')"

- job-template:
    name: 'osmo-gsm-tester_build-{repo}'
    project-type: freestyle
    node: osmo-gsm-tester-build
    builders:
      - shell: |
          rm -rf docker-playground
          git clone \
            --depth=1 \
            --branch="$DOCKER_PLAYGROUND_BRANCH" \
            https://gerrit.osmocom.org/docker-playground \
            docker-playground
          git -C docker-playground log --oneline
          make -C docker-playground/osmo-gsm-tester

          docker run  \
            --rm \
            -v "$PWD:/build" \
            -v "/opt/poky-sdk:/opt/poky-sdk" \
            -v "/opt/poky-oc2g:/opt/poky-oc2g" \
            --user build \
            "$USER"/osmo-gsm-tester \
            sh -e -x -c "
              cd /build
              ./osmo-gsm-tester/contrib/jenkins-build-{repo}.sh
            "
    triggers:
      - reverse:
            jobs: '{triggered-by}'
    publishers:
      - archive:
          artifacts: '*.tgz, *.md5'
          only-if-success: 'true'
          default-excludes: false
      - email:
          recipients: pespin@sysmocom.de jenkins-notifications@lists.osmocom.org
          notify-every-unstable-build: true
    properties:
      - build-discarder:
          num-to-keep: 20
    parameters:
      - string:
          name: "OSMO_GSM_TESTER_BRANCH"
          default: "master"
          description: "Which branch/sha should be used for testing"
      - string:
          name: "DOCKER_PLAYGROUND_BRANCH"
          default: "master"
          description: "Which branch/sha should be used for building the osmo-gsm-tester docker container"
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_libosmo-abis
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_libosmocore
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_libosmo-netif
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_libosmo_sccp
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_octphy_2g_headers
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_bts
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_mgw
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_bsc
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_libasn1c
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_iuh
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_hnbgw
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_msc
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_hlr
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_pcu
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmo_trx
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_osmocom_bb
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_open5gs
      - add_param_build_branch:
         name: OSMO_GSM_TESTER_BUILD_srslte
    scm:
      - git:
          url: https://gerrit.osmocom.org/osmo-gsm-tester
          branches:
            - '$OSMO_GSM_TESTER_BRANCH'
          wipe-workspace: false
          skip-tag: true
          basedir: osmo-gsm-tester
