From 23bc829c094164315569be7c3507ed9d9557d52c Mon Sep 17 00:00:00 2001 From: Mark Vulfson Date: Thu, 9 Jul 2020 10:09:02 -0700 Subject: [PATCH] fix(jenkins): Stop or delete from queue (#811) Stop a build can mean a) stopping it or b) removing it from queue if hasn't started. Today, igor, will attempt both if the build has been started. This can cause a 500 from jenkins server which is propagated to orca which then fails to actually complete the cancellation of a pipeline. (it's mostly harmless but it can cause issues and it also generates a bunch of exception noise) This change stops the build if it was started OR removes it from the queue if it wasn't started not both --- .../igor/build/BuildController.groovy | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/BuildController.groovy b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/BuildController.groovy index 9df733ccb..d3939ae6f 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/BuildController.groovy +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/BuildController.groovy @@ -144,19 +144,19 @@ class BuildController { if (buildNumber != 0 && buildService.metaClass.respondsTo(buildService, 'stopRunningBuild')) { buildService.stopRunningBuild(jobName, buildNumber) - } - - // The jenkins api for removing a job from the queue (http:///queue/cancelItem?id=) - // always returns a 404. This try catch block insures that the exception is eaten instead - // of being handled by the handleOtherException handler and returning a 500 to orca - try { + } else { + // The jenkins api for removing a job from the queue (http:///queue/cancelItem?id=) + // always returns a 404. This try catch block insures that the exception is eaten instead + // of being handled by the handleOtherException handler and returning a 500 to orca + try { if (buildService.metaClass.respondsTo(buildService, 'stopQueuedBuild')) { - buildService.stopQueuedBuild(queuedBuild) + buildService.stopQueuedBuild(queuedBuild) } - } catch (RetrofitError e) { + } catch (RetrofitError e) { if (e.response?.status != NOT_FOUND.value()) { - throw e + throw e } + } } }