---
- project:
    name: ci-apps-AGL
    aglbranch:
      - master
      - eel
      - dab
    architecture:
      - aarch64
        #= dragonboard-410c (disabled for dab atm)
      - x86-64
        #= intel-corei7-64
        #= qemux86-64
      - arm
        #= porter-nogfx
        #= raspberrypi3
        #= dra7xx-evm
        # ####### REPLACE WITH generic-aarch64, generic-x86-64, generic-arm
    project:
      - agl-service-audio-4a
      - agl-service-audio-mpcd
      - agl-service-bluetooth
      - agl-service-data-persistence
      - agl-service-geoclue
      - agl-service-geofence
      - agl-service-gps
      - agl-service-gstreamer
      - agl-service-homescreen-2017
      - agl-service-identity-agent
      - agl-service-mediaplayer
      - agl-service-mediascanner
      - agl-service-nfc
      - agl-service-radio
      - agl-service-signal-composer
      - agl-service-soundmanager-2017
      - agl-service-steering-wheel
      - agl-service-unicens
      - agl-service-wifi
      - agl-service-windowmanager-2017
      - als-meter-demo
      #- app-afb-helpers-submodule
      #- app-controller-submodule
      #- app-templates
      #- chromium
      - controls
      - dashboard
      - homescreen
      - hvac
      - low-level-can-service
      - mediaplayer
      - mixer
      - navigation
      - onscreenapp
      - phone
      - radio
      - settings
      - settings-bluetooth
      - settings-wifi
      - videoplayer
    jobs:
      - ci-apps-{project}-verify-{aglbranch}
      - ci-apps-{project}-verify-{aglbranch}-CIB-{architecture}
      - ci-apps-{project}-verify-{aglbranch}-CIB-finish-success
      - ci-apps-{project}-verify-{aglbranch}-failure
      - ci-apps-{project}-remove-{aglbranch}-artifacts
      - ci-apps-{project}-merge-{aglbranch}
      - ci-apps-{project}-merge-{aglbranch}-{architecture}
      - ci-apps-{project}-merge-{aglbranch}-finish-success
      # currently unused templates
      # - ci-apps-{project}-verify-CIB-start
      # - ci-apps-{project}-verify-CIBT-start
      #- ci-apps-{project}-verify-CIBT-{architecture}
      #- ci-apps-{project}-verify-CIBT-finish-success


################################################################################################################################################################
################################################################################################################################################################

################# VERIFY #################

################################################################################
# ci-apps-{project}-verify  =  trigger from gerrit and control job
################################################################################
- job-template:
    name: 'ci-apps-{project}-verify-{aglbranch}'
    project-type: multijob
    concurrent: true
    node: control-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: '{aglbranch}'
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: 'refs/heads/{aglbranch}'
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"
      - string:
          name: AGLBRANCH
          default: '{aglbranch}'
          description: "AGL release branch to use"
    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5
    triggers:
      - gerrit-trigger-patch-submitted-manual-verified:
          name: 'apps/{project}'
          branch: '{aglbranch}'
          silent: 'true'
    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
    builders:
      - shell: |
          set
          export TRIGGERURL=$(echo ${{BUILD_URL}} | sed -e 's,-CIB-start.*,,')
          echo \$TRIGGERURL
          ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} --verified=0 -n NONE --message="CI-cycle\ started.\ URL:\ ${{BUILD_URL}}" || true
          # - multijob:
          #     name: CIB-{project}-start
          #     condition: SUCCESSFUL
          #     projects:
          #       - name: 'ci-apps-{project}-verify-CIB-start'
          #         current-parameters: true
          #         abort-all-job: true
          #         kill-phase-on: FAILURE
      - multijob:
          name: CIB-{project}
          condition: SUCCESSFUL
          projects:
            - name: 'ci-apps-{project}-verify-{aglbranch}-CIB-arm'
              current-parameters: true
              #abort-all-job: true
              kill-phase-on: FAILURE
              predefined-parameters: AGLBRANCH={aglbranch}
            - name: 'ci-apps-{project}-verify-{aglbranch}-CIB-aarch64'
              current-parameters: true
              #abort-all-job: true
              kill-phase-on: FAILURE
              predefined-parameters: AGLBRANCH={aglbranch}
            - name: 'ci-apps-{project}-verify-{aglbranch}-CIB-x86-64'
              current-parameters: true
              #abort-all-job: true
              kill-phase-on: FAILURE
              predefined-parameters: AGLBRANCH={aglbranch}
      - multijob:
          name: CIB-{project}-{aglbranch}-finish-success
          condition: SUCCESSFUL
          projects:
            - name: 'ci-apps-{project}-verify-{aglbranch}-CIB-finish-success'
              current-parameters: true
              abort-all-job: true
              kill-phase-on: FAILURE


################################################################################
# ci-apps-{project}-verify-CIB-{architecture}  =  build job per arch
################################################################################
- job-template:
    name: 'ci-apps-{project}-verify-{aglbranch}-CIB-{architecture}'
    project-type: freestyle
    concurrent: true
    node: agl-test-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: '{aglbranch}'
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: refs/heads/{aglbranch}
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: ""
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: ""
          description: "patchset # to build"
      - string:
          name: TARGETARCH
          default: '{architecture}'
          description: "Machine to build"
      - string:
          name: AGLBRANCH
          default: '{aglbranch}'
          description: "AGL release branch to use"

    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5

    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
      - openstack:
          single-use: true

    builders:
      - shell:
          # including from ../common into ci-apps-{project}-verify-{aglbranch}-CIB-{architecture}
          !include-raw-escape:
          - ../common/include-apps-header.sh
          - ../common/include-apps-fetch-install-sdk.sh
          - ../common/include-apps-build-app.sh
          - ../common/include-apps-prepare-upload-folder.sh
          - ../common/include-apps-rsync-download-changeid.sh

    publishers:
      - naginator:
          rerun-unstable-builds: true
          progressive-delay-increment: 5
          progressive-delay-maximum: 15
          max-failed-builds: 2
          #regular-expression: "Unexpected termination of the channel"


################################################################################
# ci-apps-{project}-verify-CIB-finish-succcess  =  success, msg to gerrit
################################################################################
- job-template:
    name: 'ci-apps-{project}-verify-{aglbranch}-CIB-finish-success'
    project-type: freestyle
    concurrent: true
    node: control-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: '{aglbranch}'
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: 'refs/heads/{aglbranch}'
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"
      - string:
          name: AGLBRANCH
          default: '{aglbranch}'
          description: "AGL release branch to use"
    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5
    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
    builders:
      - shell: |
          set
          echo "#### CIB +1 #### Verified +1 ####"
          ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} --verified +1 --label ci-image-build=+1 -n NONE --message="CI-Image-Build\ finished,\ CIB+1,\ Verified+1.\ Artifacts\ available\ at\ https://download.automotivelinux.org/AGL/upload/ci/${{GERRIT_CHANGE_NUMBER}}/${{GERRIT_PATCHSET_NUMBER}}/\ ." || true


################################################################################
# ci-apps-{project}-verify-failure  =  message back to gerrit on failure
################################################################################
- job-template:
    name: 'ci-apps-{project}-verify-{aglbranch}-failure'
    project-type: freestyle
    concurrent: true
    node: control-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: '{aglbranch}'
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: refs/heads/{aglbranch}
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"
    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5
    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
    builders:
      - shell: |
          set
          echo "#### Verified -1 ####"
          #ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} --verified -1 -n NONE --message="CI-cycle\ failed.\ URL:\ ${{BUILD_URL}}" || true
          ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} -n NONE --message="CI-cycle\ failed.\ URL:\ ${{BUILD_URL}}" || true



################################################################################################################################################################
################################################################################################################################################################

################# REMOVE #################


#####################################################
# -remove-artifacts = merge/abandon, remove artifacts
#####################################################
- job-template:
    name: 'ci-apps-{project}-remove-{aglbranch}-artifacts'
    project-type: freestyle
    concurrent: true
    node: control-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: '{aglbranch}'
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: refs/heads/{aglbranch}
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "9551"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"
    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5
    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
      - openstack:
          single-use: false
    triggers:
      - gerrit-trigger-silent-patch-merged-abandoned:
          name: 'apps/{project}'
          branch: 'refs/heads/{aglbranch}'
    builders:
      - shell:
          !include-raw-escape:
          - ../common/include-agl-remove-artifacts-changeid.sh





################################################################################################################################################################
################################################################################################################################################################

################# MERGE #################

################################################################################
# ci-apps-{project}-merge  =  trigger from gerrit and control job
################################################################################
- job-template:
    name: 'ci-apps-{project}-merge-{aglbranch}'
    project-type: multijob
    concurrent: true
    node: control-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: '{aglbranch}'
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: 'refs/heads/{aglbranch}'
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"
      - string:
          name: AGLBRANCH
          default: '{aglbranch}'
          description: "AGL release branch to use"
    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5
    triggers:
      - gerrit-trigger-silent-patch-merged:
          name: 'apps/{project}'
          branch: '{aglbranch}'
    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
    builders:
      - multijob:
          name: CI-merge-{project}
          condition: SUCCESSFUL
          projects:
            - name: 'ci-apps-{project}-merge-{aglbranch}-arm'
              current-parameters: true
              #abort-all-job: true
              kill-phase-on: FAILURE
              predefined-parameters: AGLBRANCH={aglbranch}
            - name: 'ci-apps-{project}-merge-{aglbranch}-aarch64'
              current-parameters: true
              #abort-all-job: true
              kill-phase-on: FAILURE
              predefined-parameters: AGLBRANCH={aglbranch}
            - name: 'ci-apps-{project}-merge-{aglbranch}-x86-64'
              current-parameters: true
              #abort-all-job: true
              kill-phase-on: FAILURE
              predefined-parameters: AGLBRANCH={aglbranch}
      - multijob:
          name: CIB-{project}-{aglbranch}-finish-success
          condition: SUCCESSFUL
          projects:
            - name: 'ci-apps-{project}-merge-{aglbranch}-finish-success'
              current-parameters: true
              abort-all-job: true
              kill-phase-on: FAILURE


################################################################################
# ci-apps-{project}-merge-CIB-{architecture}  =  build job per arch
################################################################################
- job-template:
    name: 'ci-apps-{project}-merge-{aglbranch}-{architecture}'
    project-type: freestyle
    concurrent: true
    node: agl-test-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: '{aglbranch}'
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: refs/heads/{aglbranch}
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: ""
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: ""
          description: "patchset # to build"
      - string:
          name: TARGETARCH
          default: '{architecture}'
          description: "Machine to build"
      - string:
          name: AGLBRANCH
          default: '{aglbranch}'
          description: "AGL release branch to use"

    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5

    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
      - openstack:
          single-use: true

    builders:
      - shell:
          # including from ../common into ci-apps-{project}-merge-{aglbranch}-CIB-{architecture}
          !include-raw-escape:
          - ../common/include-apps-header.sh
          - ../common/include-apps-fetch-install-sdk.sh
          - ../common/include-apps-build-app.sh
          - ../common/include-apps-prepare-upload-folder-merged.sh
          - ../common/include-apps-rsync-download-apprepo.sh

    publishers:
      - naginator:
          rerun-unstable-builds: true
          progressive-delay-increment: 5
          progressive-delay-maximum: 15
          max-failed-builds: 2
          #regular-expression: "Unexpected termination of the channel"


################################################################################
# ci-apps-{project}-merge-finish-succcess  =  success, msg to gerrit
################################################################################
- job-template:
    name: 'ci-apps-{project}-merge-{aglbranch}-finish-success'
    project-type: freestyle
    concurrent: true
    node: control-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: '{aglbranch}'
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: 'refs/heads/{aglbranch}'
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"
      - string:
          name: AGLBRANCH
          default: '{aglbranch}'
          description: "AGL release branch to use"
    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5
    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
    builders:
      - shell: |
          ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} --verified +1 --label ci-image-build=+1 -n NONE --message="Merge\ finished,\ Artifacts\ available\ at\ https://download.automotivelinux.org/AGL/apps/{project}/\ ." || true













################################################################################################################################################################
# ATTIC ###############################################################################################################################################################
################################################################################################################################################################
################################################################################################################################################################


#
# CIB-start (unused)
# ###########
- job-template:
    name: 'ci-apps-{project}-verify-CIB-start'
    project-type: freestyle
    concurrent: true
    node: control-slave
    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: master
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: refs/heads/master
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"
    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5
    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
      - openstack:
          single-use: false
    builders:
      - shell: |
          #set
          export TRIGGERURL=$(echo ${{BUILD_URL}} | sed -e 's,-CIB-start.*,,')
          # ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} --verified=0 --label ci-image-build=0 --label ci-image-boot-test=0 -n NONE --message="CI-Image-Build\ started.\ URL:\ ${{BUILD_URL}}" || true
          ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} --verified=0 -n NONE --message="CI-Image-Build\ started.\ URL:\ \$TRIGGERURL" || true


#
# CIBT-{architecture} 'BOOT TEST'
# ###########################

- job-template:
    name: 'ci-apps-{project}-verify-CIBT-{architecture}'
    project-type: freestyle
    concurrent: true
    node: hwtest-slave

    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: master
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: refs/heads/master
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"
      - string:
          name: MACHINE
          default: '{architecture}'
          description: "Machine to build"

    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5

    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
      - openstack:
          single-use: false
      - credentials-binding:
          - username-password-separated:
              credential-id: agl_main_lava_instance
              username: AGLLAVAUSER
              password: AGLLAVATOKEN

    builders:
      - shell:
          # including from ../common into ci-apps-{project}-verify-CIBT-{architecture}
          !include-raw-escape:
          - ../common/include-agl-header.sh
          - ../common/include-agl-repo.sh
          - ../common/include-agl-select.sh
          - ../common/include-agl-run-test-prepare.sh
          - ../common/include-agl-lava-labs-prepare.sh
          - ../common/include-agl-run-test-short.sh
          - ../common/include-agl-lava-jobs-submit.sh

    publishers:
      - naginator:
          max-failed-builds: 2


#
# CIBT-start
# ###############

- job-template:
    name: 'ci-apps-{project}-verify-CIBT-start'
    project-type: freestyle
    concurrent: true
    node: control-slave

    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: master
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: refs/heads/master
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"

    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5

    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
      - openstack:
          single-use: false

    builders:
      - shell: |
          echo "CIBT Started"
          # set
          # ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} --label ci-image-boot-test=0 -n NONE --message='CI-Image-Boot-Test\ started' || true


#
# CIBT-finish-success
# ####################

- job-template:
    name: 'ci-apps-{project}-verify-CIBT-finish-success'
    project-type: freestyle
    concurrent: true
    node: control-slave

    parameters:
      - string:
          name: GERRIT_PROJECT
          default: 'apps/{project}'
          description: "Project to build"
      - string:
          name: GERRIT_BRANCH
          default: master
          description: "branch to build"
      - string:
          name: GERRIT_REFSPEC
          default: refs/heads/master
          description: "refspec to build"
      - string:
          name: GERRIT_CHANGE_NUMBER
          default: "8313"
          description: "change # to build"
      - string:
          name: GERRIT_PATCHSET_NUMBER
          default: "2"
          description: "patchset # to build"

    build-discarder:
      days-to-keep: 30
      artifact-days-to-keep: -1
      artifact-num-to-keep: 5

    wrappers:
      - agl-infra-wrappers:
          build-timeout: '{build-timeout}'
      - openstack:
          single-use: false

    builders:
      - shell: |
          # set
          echo "#### CIBT +1 ####"
          ssh -p 29418 agl-jobbuilder@gerrit.automotivelinux.org gerrit review ${{GERRIT_CHANGE_NUMBER}},${{GERRIT_PATCHSET_NUMBER}} --verified +1 --label ci-image-build=+1 --label ci-image-boot-test=+1 -n NONE --message='CI-Image-Boot-Test\ finished' || true