From 683246643f8389f35704ed03a8a69559b531e714 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:24:57 +0000 Subject: [PATCH] feat(jenkins): Enable Jenkins job triggers for jobs in sub-folders (#1204) (#1215) - Allow triggering of Jenkins jobs that reside in sub-folders, by treating job names containing slashes as query variables. - Prior to this feature, jobs in sub-folders were not appropriately matched by the Spring framework due to slashes in their path, causing trigger requests to fail. - Include a new feature flag to determine the usage of the existing endpoint (which uses the job name as a path variable) or an updated endpoint (which takes the job name as a query parameter). Co-authored-by: Jason (cherry picked from commit 54fbbcc85a891baa7bb3769eedbf454a8b7ee03b) Co-authored-by: Raul Cristian <24556350+ciurescuraul@users.noreply.github.com> --- .../spinnaker/igor/build/BuildController.groovy | 10 ++++++++++ .../spinnaker/igor/build/BuildControllerSpec.groovy | 13 +++++++++++++ 2 files changed, 23 insertions(+) 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 d8b13ad7e..4b336a4ce 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 @@ -107,6 +107,16 @@ class BuildController { return jobStatus(buildService, master, job, buildNumber) } + @RequestMapping(value = '/builds/status/{buildNumber}/{master}') + @PreAuthorize("hasPermission(#master, 'BUILD_SERVICE', 'READ')") + GenericBuild getJobStatus( + @PathVariable String master, + @PathVariable Integer buildNumber, + @RequestParam("job") String job) { + def buildService = getBuildService(master) + return jobStatus(buildService, master, job, buildNumber) + } + @RequestMapping(value = '/builds/artifacts/{buildNumber}/{master:.+}/**') @PreAuthorize("hasPermission(#master, 'BUILD_SERVICE', 'READ')") List getBuildResults(@PathVariable String master, @PathVariable diff --git a/igor-web/src/test/groovy/com/netflix/spinnaker/igor/build/BuildControllerSpec.groovy b/igor-web/src/test/groovy/com/netflix/spinnaker/igor/build/BuildControllerSpec.groovy index 30660a058..8553c4943 100644 --- a/igor-web/src/test/groovy/com/netflix/spinnaker/igor/build/BuildControllerSpec.groovy +++ b/igor-web/src/test/groovy/com/netflix/spinnaker/igor/build/BuildControllerSpec.groovy @@ -129,6 +129,19 @@ class BuildControllerSpec extends Specification { response.contentAsString == "{\"building\":false,\"number\":${BUILD_NUMBER}}" } + void 'get the status of a build with job name as query parameter'() { + given: + 1 * service.getGenericBuild(JOB_NAME, BUILD_NUMBER) >> new GenericBuild(building: false, number: BUILD_NUMBER) + + when: + MockHttpServletResponse response = mockMvc.perform(get("/builds/status/${BUILD_NUMBER}/${SERVICE}") + .param("job", JOB_NAME) + .accept(MediaType.APPLICATION_JSON)).andReturn().response + + then: + response.contentAsString == "{\"building\":false,\"number\":${BUILD_NUMBER}}" + } + void 'get an item from the queue'() { given: 1 * jenkinsService.queuedBuild(_, QUEUED_JOB_NUMBER) >> new QueuedJob(executable: [number: QUEUED_JOB_NUMBER])