From ecf01a70ea2be180ea6e4077e4f2bb3ba4ef3698 Mon Sep 17 00:00:00 2001 From: Phillip Johnsen Date: Wed, 5 Jun 2019 22:34:22 +0200 Subject: [PATCH] jenkins: destructure build result after knowing it's not an error We've seen some error logs in production suggesting that we get errors back from Jenkins when triggering builds, as the result is `null | undefined`. Destructuring fields out of that result causes unchaught exceptions, meaning the bot process dies. Therefore postponing the destructuring until we're confident the build didn't result in an error. --- scripts/trigger-jenkins-build.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/trigger-jenkins-build.js b/scripts/trigger-jenkins-build.js index 11d0cf4b..6d9cdf40 100644 --- a/scripts/trigger-jenkins-build.js +++ b/scripts/trigger-jenkins-build.js @@ -82,15 +82,18 @@ function triggerBuildIfValid (options) { return logger.debug(`Ignoring comment to me by @${options.author} because they are not a repo collaborator`) } - triggerBuild(options, function onBuildTriggered (err, { jobName, jobId }) { - const jobUrl = `https://ci.nodejs.org/job/${jobName}/${jobId}` - let body = `Lite-CI: ${jobUrl}` + triggerBuild(options, function onBuildTriggered (err, result) { + let body = '' + if (err) { logger.error(err, 'Error while triggering Jenkins build') body = 'Sadly, an error occurred when I tried to trigger a build. :(' } else { + const jobUrl = `https://ci.nodejs.org/job/${result.jobName}/${result.jobId}` logger.info({ jobUrl }, 'Jenkins build started') + body = `Lite-CI: ${jobUrl}` } + createPrComment(options, body) }) })