- job:
    name: jdk-clean-job
    project-type: freestyle
    defaults: global
    description: |
        Clean up the machine after or before other jobs.
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            openjdk-members:
                - job-build
                - job-cancel
        - build-discarder:
            num-to-keep: 10
            artifact-num-to-keep: 1
    disabled: true
    node: j12-qrep-01
    display-name: 'DELETE ME'
    wrappers:
        - timestamps
    builders:
        - shell: |
            #!/bin/bash
            #set -exu

            # Kill all orphaned java processes
            ps --no-headers --ppid 1 --format "pid cmd"  | tr -s " " | grep java | cut -d " " -f 1 | xargs kill -9

            # Kill all jstatd processes. These can accumulate.
            killall --verbose -9 jstatd

            # Javac jobs can accumulate.
            killall --verbose -9 javac

            # These can accumulate too.
            killall --verbose -9 Xvfb

            ps --forest -aux
    publishers:
        - email:
            recipients: 'stuart.monteith@linaro.org'
