From 36758532aee2c9f1e89b7c8fa8e4afd180d2f335 Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Jul 26 2018 17:37:33 +0000 Subject: add a PR pipeline --- diff --git a/.cico-pr.pipeline b/.cico-pr.pipeline new file mode 100644 index 0000000..f6beab8 --- /dev/null +++ b/.cico-pr.pipeline @@ -0,0 +1,91 @@ +import groovy.json.JsonOutput + +def notifyPagurePR(repo, msg, status, phase, credentials = 'pagure-auth'){ + def json = JsonOutput.toJson([name: 'pagure', url: env.JOB_NAME, build: [full_url: currentBuild.absoluteUrl, status: status, number: currentBuild.number, phase: phase]]) + println json + + withCredentials([string(credentialsId: credentials, variable: "PAGURE_PUSH_SECRET")]) { + /* We need to notify pagure that jenkins finished but then pagure will + wait for jenkins to be done, so if we wait for pagure's answer we're + basically stuck in a loop where both jenkins and pagure are waiting + for each other */ + 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" + } +} + +def onmyduffynode(script){ + ansiColor('xterm'){ + timestamps{ + sh 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root ${DUFFY_NODE}.ci.centos.org -t "' + script + '"' + } + } +} + +def syncfromduffynode(rsyncpath){ + sh 'rsync -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root " -Ha --include=' + rsyncpath + " ${DUFFY_NODE}.ci.centos.org:~/ ./" +} + +node('factory2'){ + + properties([ + parameters([ + string(defaultValue: "", description: "", name: "REPO"), + string(defaultValue: "", description: "", name: "BRANCH"), + ]) + ]) + + stage('Allocate Node'){ + env.CICO_API_KEY = readFile("${env.HOME}/duffy.key").trim() + duffy_rtn=sh( + script: 'cico --debug node get -f value -c hostname -c comment', + returnStdout: true + ).trim().tokenize(' ') + env.DUFFY_NODE=duffy_rtn[0] + env.SSID=duffy_rtn[1] + } + + try{ + stage('Pre Setup Node'){ + // Install EPEL and the SCLs repo + onmyduffynode 'yum -y install git docker && systemctl start docker' + } + + stage('Clone Test Suite') { + onmyduffynode "git clone -b \"${env.BRANCH_NAME}\" --single-branch --depth 1 https://pagure.io/fm-orchestrator" + + onmyduffynode "cd fm-orchestrator && git remote add proposed \"${env.REPO}\"" + onmyduffynode "cd fm-orchestrator && git fetch proposed" + onmyduffynode "cd fm-orchestrator && git checkout origin master" + onmyduffynode "cd fm-orchestrator && git config --global user.email ci@centos.org" + onmyduffynode "cd fm-orchestrator && git config --global user.name CentOS CI" + onmyduffynode "cd fm-orchestrator && git merge --no-ff \"proposed/${env.BRANCH}\" -m \"Merge PR\"" + onmyduffynode "cd fm-orchestrator && git log -2" + + + } + + stage('Build Docker Image') { + onmyduffynode 'cd fm-orchestrator && docker build -t mbs/test -f docker/Dockerfile-tests .' + } + + stage('Run Test Suite') { + timeout(20) { + onmyduffynode 'docker run -v ~/fm-orchestrator:/src:Z mbs/test' + } + } + + }catch (e){ + currentBuild.result = "FAILED" + throw e + } finally { + stage('Deallocate Node'){ + sh 'cico node done ${SSID}' + } + + stage('Notify PR'){ + res = currentBuild.currentResult + notifyPagurePR("fm-orchestrator", "Build " + res + "! ", res, "FINALIZED") + } + + } +}