Blame .cico.pipeline

Brian Stinson 4c7aaa
import groovy.json.JsonOutput
Brian Stinson 4c7aaa
Pierre-Yves Chibon ec38e4
def notifyPagurePR(repo, msg, status, phase, credentials = 'pagure-auth'){
Pierre-Yves Chibon ec38e4
    def json = JsonOutput.toJson([name: 'pagure', url: env.JOB_NAME, build: [full_url: currentBuild.absoluteUrl, status: status, number: currentBuild.number, phase: phase]])
Brian Stinson 4c7aaa
    println json
Brian Stinson 4c7aaa
Brian Stinson a84647
    withCredentials([string(credentialsId: credentials, variable: "PAGURE_PUSH_SECRET")]) {
Pierre-Yves Chibon 8f6c04
        /* We need to notify pagure that jenkins finished but then pagure will
Pierre-Yves Chibon 8f6c04
          wait for jenkins to be done, so if we wait for pagure's answer we're
Pierre-Yves Chibon 8f6c04
          basically stuck in a loop where both jenkins and pagure are waiting
Pierre-Yves Chibon 8f6c04
          for each other */
Pierre-Yves Chibon 5f4018
        sh "timeout 1 curl -X POST -d \'$json\' https://pagure.io/api/0/ci/jenkins/$repo/${PAGURE_PUSH_SECRET}/build-finished -H \"Content-Type: application/json\" | true"
Brian Stinson 4c7aaa
    }
Brian Stinson 4c7aaa
}
Brian Stinson 4c7aaa
Pierre-Yves Chibon d637dc
def onmyduffynode(script){
Pierre-Yves Chibon d637dc
    ansiColor('xterm'){
Pierre-Yves Chibon d637dc
        timestamps{
Brian Stinson 3cf08c
            sh 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root ${DUFFY_NODE}.ci.centos.org -t \"export REPO=${REPO}; export BRANCH=${BRANCH};\" "' + script + '"'
Pierre-Yves Chibon d637dc
        }
Pierre-Yves Chibon d637dc
    }
Pierre-Yves Chibon d637dc
}
Pierre-Yves Chibon d637dc
Pierre-Yves Chibon d637dc
def syncfromduffynode(rsyncpath){
Pierre-Yves Chibon d637dc
    sh 'rsync -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root " -Ha --include=' +  rsyncpath +  " ${DUFFY_NODE}.ci.centos.org:~/ ./"
Pierre-Yves Chibon d637dc
}
Pierre-Yves Chibon d637dc
Pierre-Yves Chibon d637dc
node('pagure') {
Pierre-Yves Chibon d637dc
Brian Stinson f850c4
    properties([
Brian Stinson f850c4
            parameters([
Brian Stinson f850c4
                string(defaultValue: "", description: "", name: "REPO"),
Brian Stinson f850c4
                string(defaultValue: "", description: "", name: "BRANCH"),
Brian Stinson f850c4
                ])
Brian Stinson f850c4
            ])
Brian Stinson f850c4
Pierre-Yves Chibon d637dc
    stage('Allocate Node'){
Pierre-Yves Chibon d637dc
        env.CICO_API_KEY = readFile("${env.HOME}/duffy.key").trim()
Pierre-Yves Chibon d637dc
        duffy_rtn=sh(
Pierre-Yves Chibon d637dc
            script: 'cico --debug node get -f value -c hostname -c comment',
Pierre-Yves Chibon d637dc
            returnStdout: true
Pierre-Yves Chibon d637dc
            ).trim().tokenize(' ')
Pierre-Yves Chibon d637dc
        env.DUFFY_NODE=duffy_rtn[0]
Pierre-Yves Chibon d637dc
        env.SSID=duffy_rtn[1]
Brian Stinson 44116a
        env.BRANCH=params.BRANCH
Brian Stinson 3f1380
        env.REPO=params.REPO
Pierre-Yves Chibon d637dc
    }
Pierre-Yves Chibon d637dc
Pierre-Yves Chibon d637dc
    try {
Pierre-Yves Chibon d637dc
        stage('Pre Setup Node'){
Pierre-Yves Chibon d637dc
            // Install EPEL
Pierre-Yves Chibon e18a1b
            onmyduffynode 'yum -y install epel-release git'
Pierre-Yves Chibon d637dc
        }
Pierre-Yves Chibon d637dc
Pierre-Yves Chibon ec38e4
        stage('Notify PR'){
Pierre-Yves Chibon ec38e4
            notifyPagurePR("pagure", "Tests running ", "BUILDING", "STARTED")
Pierre-Yves Chibon ec38e4
        }
Pierre-Yves Chibon ec38e4
Pierre-Yves Chibon d637dc
        stage('Clone Test Suite') {
Brian Stinson 44116a
            onmyduffynode "git clone --single-branch --depth 1 https://pagure.io/pagure.git"
Pierre-Yves Chibon d637dc
        }
Pierre-Yves Chibon d637dc
Pierre-Yves Chibon d637dc
        stage('Run Test Suite') {
Pierre-Yves Chibon e18a1b
            timeout(time: 6, unit: 'HOURS') {
Pierre-Yves Chibon 233af4
                onmyduffynode 'cd pagure && sh ./run_ci_tests.sh'
Pierre-Yves Chibon d637dc
            }
Pierre-Yves Chibon d637dc
        }
Pierre-Yves Chibon d637dc
Pierre-Yves Chibon d637dc
    } catch (e) {
Brian Stinson 4c7aaa
        currentBuild.result = "FAILURE"
Pierre-Yves Chibon d637dc
        throw e
Pierre-Yves Chibon d637dc
    } finally {
Brian Stinson 62de45
        stage('Sync Artifacts'){
Brian Stinson 62de45
            syncfromduffynode('pagure/*.out')
Brian Stinson 62de45
        }
Brian Stinson 62de45
Pierre-Yves Chibon d637dc
        stage('Deallocate Node'){
Pierre-Yves Chibon d637dc
            sh 'cico node done ${SSID}'
Pierre-Yves Chibon d637dc
        }
Brian Stinson 62de45
Brian Stinson 4c7aaa
        stage('Notify PR'){
Brian Stinson 4c7aaa
            res = currentBuild.currentResult
Pierre-Yves Chibon ec38e4
            notifyPagurePR("pagure", "Build " + res + "! ", res, "FINALIZED")
Brian Stinson 4c7aaa
        }
Brian Stinson 4c7aaa
Brian Stinson 62de45
        stage('Archive Artifacts'){
Pierre-Yves Chibon 463e17
            archiveArtifacts artifacts: 'pagure/*.out'
Brian Stinson 62de45
        }
Pierre-Yves Chibon d637dc
    }
Pierre-Yves Chibon d637dc
}