- scm:
    name: poky
    scm:
        - git:
            url: https://git.yoctoproject.org/git/poky
            refspec: +refs/heads/${BRANCH}:refs/remotes/origin/${BRANCH}
            name: origin
            branches:
                - refs/heads/${BRANCH}
            shallow-clone: true
            wipe-workspace: false
- scm:
    name: meta-xilinx
    scm:
        - git:
            url: https://github.com/Xilinx/meta-xilinx.git
            refspec: +refs/heads/${BRANCH}:refs/remotes/origin/${BRANCH}
            name: origin
            branches:
                - refs/heads/${BRANCH}
            basedir: meta-xilinx
            shallow-clone: true
            wipe-workspace: false
- job:
    name: lite-openembedded-zcu102-rocko
    project-type: freestyle
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 30
            artifact-num-to-keep: 1
    parameters:
        - string:
            name: MACHINE
            default: 'zcu102-zynqmp'
        - string:
            name: DISTRO
            default: 'poky'
        - string:
            name: BRANCH
            default: 'rocko'
        - string:
            name: BASE_URL
            default: 'http://snapshots.linaro.org/'
        - string:
            name: PUB_DEST
            default: 'openembedded/lite/${BRANCH}/${MACHINE}/${BUILD_NUMBER}/${DISTRO}'
    disabled: true
    node: docker-stretch-amd64
    display-name: 'DELETE ME'
    scm:
        - poky
        - meta-xilinx
    wrappers:
        - timestamps
        - build-name:
            name: '#${BUILD_NUMBER}-${GIT_REVISION,length=8}'
    builders:
        - shell: |
            #!/bin/bash

            set -e

            if ! sudo DEBIAN_FRONTEND=noninteractive apt -q=2 update; then
              echo "INFO: apt update error - try again in a moment"
              sleep 15
              sudo DEBIAN_FRONTEND=noninteractive apt -q=2 update || true
            fi
            pkg_list="chrpath cpio diffstat gawk libmath-prime-util-perl libsdl1.2-dev libssl-dev python-requests texinfo vim-tiny whiptail"
            if ! sudo DEBIAN_FRONTEND=noninteractive apt -q=2 install -y ${pkg_list}; then
              echo "INFO: apt install error - try again in a moment"
              sleep 15
              sudo DEBIAN_FRONTEND=noninteractive apt -q=2 install -y ${pkg_list}
            fi

            set -ex

            # link to shared downloads on persistent disk
            # our builds config is expecting downloads and sstate-cache, here.
            mkdir -p ${HOME}/srv/oe/downloads ${HOME}/srv/oe/sstate-cache-${DISTRO}-${BRANCH}
            mkdir -p build
            ln -s ${HOME}/srv/oe/downloads build/downloads
            ln -s ${HOME}/srv/oe/sstate-cache-${DISTRO}-${BRANCH} build/sstate-cache

            # Build
            source oe-init-build-env
            echo "SRCREV_pn-qemu-xilinx = \"a957a906bfdbc5c1626eedf5ffff8c8fa69bad1c\"" >> conf/local.conf
            bitbake-layers add-layer ${WORKSPACE}/meta-xilinx/meta-xilinx-bsp
            bitbake core-image-minimal

            # Prepare files to publish
            DEPLOY_DIR_IMAGE=$(bitbake -e | grep "^DEPLOY_DIR_IMAGE="| cut -d'=' -f2 | tr -d '"')
            rm -f ${DEPLOY_DIR_IMAGE}/*.txt
            find ${DEPLOY_DIR_IMAGE} -type l -delete

            cat << EOF > ${WORKSPACE}/post_build_lava_parameters
            DEPLOY_DIR_IMAGE=${DEPLOY_DIR_IMAGE}
            EOF
        - inject:
            properties-file: post_build_lava_parameters
        - linaro-publish-token
        - shell: |
            #!/bin/bash

            set -e

            # Publish
            test -d ${HOME}/bin || mkdir ${HOME}/bin
            wget -q https://git.linaro.org/ci/publishing-api.git/blob_plain/HEAD:/linaro-cp.py -O ${HOME}/bin/linaro-cp.py
            time python3 ${HOME}/bin/linaro-cp.py \
              --server ${PUBLISH_SERVER} \
              --link-latest \
            ${DEPLOY_DIR_IMAGE}/ ${PUB_DEST}
    publishers:
        - email:
            recipients: 'fathi.boudra@linaro.org jiaying.liang@linaro.org'
