- job:
    name: tcwg-buildslave-command
    project-type: freestyle
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 100
    parameters:
        - label:
            name: nodes
            default: tcwg-amp_64-build || tcwg-coordinator || tcwg-sq_64-build || tcwg-tk1_32-build || tcwg-x86_64-build || tcwg-x86_64-cam
            all-nodes: true
            matching-label: 'allCases'
            node-eligibility: 'ignore-offline'
            description: 'Machines to run on'
        - text:
            name: command
            default: |
              #!/bin/bash
              set -ex

              ls -la $HOME/
            description: 'Command to run'
        - bool:
            name: dry_run
            default: 'false'
            description: 'Whether to do a dry-run'
        - string:
            name: displayname
            default: 'unknown'
            description: 'Name to display in the Jenkins console, so that the build name is more helpful'
    disabled: false
    concurrent: true
    display-name: 'TCWG CCC Buildslave Command'
    wrappers:
        - timeout:
            timeout: 60
        - timestamps
        - ssh-agent-credentials:
            # tcwg-buildslave user id
            users:
                - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a'
                - 'tcwg-benchmark'
        - build-name:
            name: '${displayname}-${BUILD_NUMBER}-${NODE_NAME}'
    builders:
        - shell: |
            #!/bin/bash

            set -ex

            cat > command-$BUILD_NUMBER.sh << EOF
            $command
            EOF
            chmod +x command-$BUILD_NUMBER.sh

            if $dry_run; then
              cat command-$BUILD_NUMBER.sh
            else
              ./command-$BUILD_NUMBER.sh
            fi
    publishers:
        - email-ext:
            recipients: 'tcwg-validation@linaro.org'
            aborted: true
