From 58019a51345a4a647643725420e4b02f3da69556 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Fri, 3 Nov 2017 20:26:58 -0400 Subject: [PATCH] jenkins: post-build-status-update This creates a new `post-build-status-update` Jenkins Pipeline. It's job is to propogate build information from Jenkins CI to the GitHub Bot to GitHub. The pipeline created here will be called from node-test-commit-* sub build jobs through the [Parameterized Trigger Plugin](https://wiki.jenkins.io/display/JENKINS/Parameterized+Trigger+Plugin). The way this would be used is by creating pre and post build triggers through the plugin, which would call this pipeline. My suggestion is that we woll this out to one or two jobs (maybe the linter?), try it out, and then after that roll it out to all sub builds. Hopefully, this PR should finally fix the yellow CI statuses on GitHub! PR-URL: https://github.com/nodejs/build/pull/973 Refs: https://github.com/nodejs/build/issues/790 Reviewed-By: Gibson Fahnestock Reviewed-By: Refael Ackermann --- .../post-build-status-update.jenkinsfile | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 jenkins/pipelines/post-build-status-update.jenkinsfile diff --git a/jenkins/pipelines/post-build-status-update.jenkinsfile b/jenkins/pipelines/post-build-status-update.jenkinsfile new file mode 100644 index 000000000..7a9e58048 --- /dev/null +++ b/jenkins/pipelines/post-build-status-update.jenkinsfile @@ -0,0 +1,70 @@ +#!/usr/bin/env groovy + +// DESCRIPTION: +// Sends the status of a node-test-commit-* sub build to the Github Bot, which +// then updates the corresponding PR's CI status on github.com. + +import groovy.json.JsonOutput + +pipeline { + agent { label 'jenkins-workspace' } + + parameters { + string(defaultValue: '', description: 'test/aix, linter, etc.', name: 'IDENTIFIER') + string(defaultValue: '', description: 'pending, success, unstable, failure', name: 'STATUS') + string(defaultValue: '', description: 'URL for upstream Jenkins job', name: 'URL') + string(defaultValue: '', description: 'Current commit being tested in upstream Jenkins job', name: 'COMMIT') + string(defaultValue: '', description: 'Current branch being tested in upstream Jenkins job', name: 'REF') + } + + stages { + stage('Send status report') { + steps { + validateParams(params) + sendBuildStatus(params.IDENTIFIER, params.STATUS, params.URL, params.COMMIT, params.REF) + } + } + } +} + +def sendBuildStatus(identifier, status, url, commit, ref) { + def path = "" + def message = "" + + if (status == "pending") { + path = "start" + message = "running tests" + } else if (status == "failure") { + path = "end" + message = "tests failed" + } else if (status == "unstable") { + path = "end" + message = "flaky tests failed" + status = "success" + } else if (status == "success") { + path = "end" + message = "tests passed" + } + + def buildPayload = JsonOutput.toJson([ + 'identifier': identifier, + 'status': status, + 'url': url, + 'commit': commit, + 'ref': ref, + 'message': message + ]) + + def script = "curl -s -o /dev/null --connect-timeout 5 -X POST " + + "-H 'Content-Type: application/json' -d '${buildPayload}' " + + "http://github-bot.nodejs.org:3333/node/jenkins/${path}" + + sh(returnStdout: true, script: script) +} + +def validateParams(params) { + if (params.IDENTIFIER == '' || params.STATUS == '' || params.URL == '' || + params.COMMIT == '' || params.REF == '') { + error('All parameter fields are required.') + } +}