From 01a46c3275feb02ad2d34a2682b75855535e16b4 Mon Sep 17 00:00:00 2001 From: Adam Lebsack Date: Tue, 22 Nov 2016 11:02:50 +0100 Subject: [PATCH] Report status of each step to github --- Jenkinsfile | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4c3ab071..3f1c7f3f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -69,30 +69,45 @@ stage('check') { } } +def reportStatus(target, state, message) { + step([ + $class: 'GitHubCommitStatusSetter', + contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: target], + statusResultSource: [$class: 'ConditionalStatusResultSource', results: [[ + $class: 'AnyBuildResult', message: message, state: state]] + ], + reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/realm/realm-js'] + ]) +} + +def doInside(script, target, postStep = null) { + try { + reportStatus(target, 'PENDING', 'Build has started') + getSourceArchive() + sh "bash ${script} ${target}" + if(postStep) { + postStep.call() + } + + reportStatus(target, 'SUCCESS', 'Success!') + } catch(Exception e) { + reportStatus(target, 'FAILURE', e.toString()) + currentBuild.rawBuild.setResult(Result.FAILURE) + } +} + def doDockerBuild(target, postStep = null) { return { - timeout(50) { // minutes - node('docker') { - getSourceArchive() - sh "bash scripts/docker-test.sh ${target}" - if(postStep) { - postStep.call() - } - } + node('docker') { + doInside('scripts/docker-test.sh', target, postStep) } } } def doBuild(nodeSpec, target, postStep = null) { return { - timeout(50) { // minutes - node(nodeSpec) { - getSourceArchive() - sh "bash scripts/test.sh ${target}" - if(postStep) { - postStep.call() - } - } + node(nodeSpec) { + doInside('scripts/test.sh', target, postStep) } } }