- project:
    name: tcwg_monitoring_disk_users
    slave_name:
      - dev-01.tcwglab
      - tcwg-ex42-01
      - tcwg-amp-02.tcwglab
    jobs:
      - 'tcwg_monitoring_disk_users_{slave_name}'

- view:
    name: tcwg_monitoring
    view-type: list
    regex: 'tcwg_monitoring_.*'

- property:
    name: default-properties
    properties:
      - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-build
                - job-cancel
      - build-discarder:
          days-to-keep: 30
          num-to-keep: 300

- parameter:
    name: default-parameters
    parameters:
      - string:
          name: scripts_branch
          default: master
          description: 'Scripts revision to use'
      - string:
          name: TIMEOUT
          default: 0
          description: 'Timeout to use when computing disk usage'
      - bool:
          name: verbose
          default: false
          description: 'Whether to be verbose'
      - bool:
          name: sendmail
          default: true
          description: 'Whether send a mail'

- scm:
    name: jenkins
    scm:
      - git:
          url: https://gitlab.com/LinaroLtd/tcwg/monitoring-scripts.git
          refspec: +refs/heads/*:refs/remotes/origin/* +refs/changes/*:refs/changes/*
          branches:
            - $scripts_branch
          skip-tag: true
          wipe-workspace: true

- job-template:
    name: tcwg_monitoring_disk_users_{slave_name}
    project-type: freestyle
    defaults: global
    properties:
      - default-properties
    parameters:
      - default-parameters
    disabled: false
    node: tcwg-coordinator
    concurrent: true
    display-name: 'TCWG Monitoring top disk users {slave_name}'
    scm:
      - jenkins
    triggers:
        - timed: '@daily'
    wrappers:
      - timeout:
          timeout: 600
      - timestamps
      - ssh-agent-credentials:
          # tcwg-buildslave user id
          users:
            - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a'
      - build-name:
          name: '#$BUILD_NUMBER-{slave_name}'
    builders:
        - shell: |
            #!/bin/bash
            set -ex -o pipefail
            slave_name={slave_name}
            if $verbose; then
              export DEBUG=true
            fi
            ./top-disk-one-slave.sh $slave_name | tee mail-body.txt
            # We normally send an email upon failure only, so exit
            #  with 0 if we don't want to send a mail
            if ! $sendmail; then
              exit 0
            fi
    publishers:
        - email-ext:
            recipients: tcwg@linaro.org
            content-type: text
            body: |
              ${{FILE,path="mail-body.txt"}}
            aborted: true
