From dd8290e03a95095262d3b3b0fd10717c047534fe Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Fri, 3 Nov 2017 20:26:58 -0400 Subject: [PATCH 1/6] 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! Refs: https://github.com/nodejs/build/issues/790 --- jenkins/post-build-status-update.jenkinsfile | 50 ++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 jenkins/post-build-status-update.jenkinsfile diff --git a/jenkins/post-build-status-update.jenkinsfile b/jenkins/post-build-status-update.jenkinsfile new file mode 100644 index 000000000..ad50a5dd0 --- /dev/null +++ b/jenkins/post-build-status-update.jenkinsfile @@ -0,0 +1,50 @@ +#!/usr/bin/env groovy + +import groovy.json.JsonOutput + +pipeline { + agent { label 'jenkins-workspace' } + + parameters { + string(defaultValue: '', description: 'test/aix, linter, etc.', name: 'IDENTIFIER') + string(defaultValue: '', description: 'pending, success, 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 { + 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 == "success") { + path = "end" + message = "tests passed" + } + + def buildPayload = JsonOutput.toJson([ + 'identifier': identifier, + 'status': status, + 'url': url, + 'commit': commit, + 'ref': ref, + 'message': message + ]) + + sh(returnStdout: true, 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}") +} From ac5f261e7883ec7180950c564d19fb745e8facc6 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 4 Nov 2017 09:56:44 -0400 Subject: [PATCH 2/6] fix comments --- jenkins/post-build-status-update.jenkinsfile | 21 ++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/jenkins/post-build-status-update.jenkinsfile b/jenkins/post-build-status-update.jenkinsfile index ad50a5dd0..0bd76663b 100644 --- a/jenkins/post-build-status-update.jenkinsfile +++ b/jenkins/post-build-status-update.jenkinsfile @@ -1,5 +1,9 @@ #!/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 { @@ -16,7 +20,11 @@ pipeline { stages { stage('Send status report') { steps { - sendBuildStatus(params.IDENTIFIER, params.STATUS, params.URL, params.COMMIT, params.REF) + if (validParams(params)) { + sendBuildStatus(params.IDENTIFIER, params.STATUS, params.URL, params.COMMIT, params.REF) + } else { + error('All parameter fields are required.) + } } } } @@ -46,5 +54,14 @@ def sendBuildStatus(identifier, status, url, commit, ref) { 'message': message ]) - sh(returnStdout: true, 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}") + 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 validParams(params) { + params.IDENTIFIER != '' || params.STATUS != '' || params.URL != '' || + params.COMMIT != '' || params.REF != '' } From a2059dec73dd6221395fef1714a0d8e541c471a2 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 4 Nov 2017 10:48:56 -0400 Subject: [PATCH 3/6] nit: show different message for unstable builds --- jenkins/post-build-status-update.jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jenkins/post-build-status-update.jenkinsfile b/jenkins/post-build-status-update.jenkinsfile index 0bd76663b..c05975804 100644 --- a/jenkins/post-build-status-update.jenkinsfile +++ b/jenkins/post-build-status-update.jenkinsfile @@ -11,7 +11,7 @@ pipeline { parameters { string(defaultValue: '', description: 'test/aix, linter, etc.', name: 'IDENTIFIER') - string(defaultValue: '', description: 'pending, success, failure', name: 'STATUS') + 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') @@ -40,6 +40,9 @@ def sendBuildStatus(identifier, status, url, commit, ref) { } else if (status == "failure") { path = "end" message = "tests failed" + } else if (status == "unstable") { + path = "end" + message = "flaky tests failed" } else if (status == "success") { path = "end" message = "tests passed" From c5cad3637d880a1a8f838d239301c3eb322c7b22 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 4 Nov 2017 10:50:14 -0400 Subject: [PATCH 4/6] change status to success if unstable --- jenkins/post-build-status-update.jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/jenkins/post-build-status-update.jenkinsfile b/jenkins/post-build-status-update.jenkinsfile index c05975804..b39815df9 100644 --- a/jenkins/post-build-status-update.jenkinsfile +++ b/jenkins/post-build-status-update.jenkinsfile @@ -43,6 +43,7 @@ def sendBuildStatus(identifier, status, url, commit, ref) { } else if (status == "unstable") { path = "end" message = "flaky tests failed" + status = "success" } else if (status == "success") { path = "end" message = "tests passed" From 55a5ebe6e7fa2b33553d695f79e0cbe55e25b36d Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 4 Nov 2017 11:02:57 -0400 Subject: [PATCH 5/6] fix syntax errors --- jenkins/post-build-status-update.jenkinsfile | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/jenkins/post-build-status-update.jenkinsfile b/jenkins/post-build-status-update.jenkinsfile index b39815df9..7a9e58048 100644 --- a/jenkins/post-build-status-update.jenkinsfile +++ b/jenkins/post-build-status-update.jenkinsfile @@ -20,11 +20,8 @@ pipeline { stages { stage('Send status report') { steps { - if (validParams(params)) { - sendBuildStatus(params.IDENTIFIER, params.STATUS, params.URL, params.COMMIT, params.REF) - } else { - error('All parameter fields are required.) - } + validateParams(params) + sendBuildStatus(params.IDENTIFIER, params.STATUS, params.URL, params.COMMIT, params.REF) } } } @@ -65,7 +62,9 @@ def sendBuildStatus(identifier, status, url, commit, ref) { sh(returnStdout: true, script: script) } -def validParams(params) { - params.IDENTIFIER != '' || params.STATUS != '' || params.URL != '' || - params.COMMIT != '' || params.REF != '' +def validateParams(params) { + if (params.IDENTIFIER == '' || params.STATUS == '' || params.URL == '' || + params.COMMIT == '' || params.REF == '') { + error('All parameter fields are required.') + } } From d61eb49262dd477bec7ae075abdd6b6c3b168adc Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 4 Nov 2017 14:41:55 -0400 Subject: [PATCH 6/6] move to jenkins/pipelines --- jenkins/{ => pipelines}/post-build-status-update.jenkinsfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename jenkins/{ => pipelines}/post-build-status-update.jenkinsfile (100%) diff --git a/jenkins/post-build-status-update.jenkinsfile b/jenkins/pipelines/post-build-status-update.jenkinsfile similarity index 100% rename from jenkins/post-build-status-update.jenkinsfile rename to jenkins/pipelines/post-build-status-update.jenkinsfile