- job:
    name: tcwg-gcc-bisect
    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: 60
    parameters:
        - string:
            name: EXP
            default: ''
            description: '.exp file name (eg. dg.exp)'
        - string:
            name: TESTNAME
            default: ''
            description: 'test name (eg. prXXXXX.c)'
        - string:
            name: TARGET
            default: ''
            description: 'Which target to build'
        - string:
            name: CPU
            default: ''
            description: '--with-cpu GCC configure option'
        - string:
            name: FPU
            default: ''
            description: '--with-fpu GCC configure option'
        - string:
            name: MODE
            default: ''
            description: '--with-mode GCC configure option (arm or thumb)'
        - string:
            name: GOODGIT
            default: ''
            description: 'Good GIT revision'
        - string:
            name: BADGIT
            default: ''
            description: 'Bad GIT revision'
        - string:
            name: build_container_tag
            default: 'lts_1'
            description: 'Distro to use on the builder: lts_1, lts, ...'
    disabled: false
    node: tcwg-x86_64-cam
    concurrent: true
    display-name: 'TCWG ZZZ GCC Bisect'
    wrappers:
        - timeout:
            timeout: 3000
        - timestamps
        - ssh-agent-credentials:
            # tcwg-buildslave user id
            users:
                - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a'
        - build-name:
            name: '#${BUILD_NUMBER}-${ENV,var="GOODGIT"}-${ENV,var="BADGIT"}-${ENV,var="TARGET"}'
    builders:
        - shell: |
            #!/bin/bash

            set -e
            set -x
            shell="/bin/bash"

            rm -rf jenkins-scripts
            git clone --depth 1 https://gitlab.com/LinaroLtd/tcwg/jenkins-scripts

            # Configure git user info to make git stash happy. It is
            # used during the second build, because the sources are
            # already present.
            git config --global user.email "tcwg-buildslave@linaro.org"
            git config --global user.name "TCWG BuildSlave"

            # Start build container
            # Force amd64 arch to workaround a bug in jenkins-helpers.sh
            bash -x ./jenkins-scripts/start-container-docker.sh --arch amd64 --node $NODE_NAME --distro ${build_container_tag} --prefix build_ > build-container.sh

            # Define build_CONTAINER_RSH and build_container_cleanup
            . ./build-container.sh

            # Make sure to cleanup build container if something goes
            # wrong when preparing the test environment
            trap "cleanup_all_containers" EXIT

            # Jenkins puts the parameters in the environment
            ${build_CONTAINER_RSH} "cd ${WORKSPACE} && EXP=$EXP TESTNAME=$TESTNAME TARGET=$TARGET CPU=$CPU FPU=$FPU MODE=$MODE GOODGIT=$GOODGIT BADGIT=$BADGIT BUILD_URL=$BUILD_URL ${shell} ${WORKSPACE}/jenkins-scripts/abe-bisect.sh"
    publishers:
        - email-ext:
            recipients: 'christophe.lyon@linaro.org'
            content-type: text
            body: |
              ${FILE,path="mail-body.txt"}
            aborted: true
            send-to:
              requester
              recipients
            always: true

