Skip to content

Commit

Permalink
feat(jenkins): Enable Jenkins job triggers for jobs in sub-folders (#…
Browse files Browse the repository at this point in the history
…1204)

- 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 <[email protected]>
  • Loading branch information
ciurescuraul and jasonmcintosh authored Dec 22, 2023
1 parent 793665f commit 54fbbcc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Artifact> getBuildResults(@PathVariable String master, @PathVariable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 54fbbcc

Please sign in to comment.