diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy index bff8e6a66d..ac15e83598 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy @@ -98,20 +98,20 @@ class PipelineController { pipelineService.startPipeline(map, authenticatedUser) } - @RequestMapping(value = "/{application}/{pipelineName:.+}", method = RequestMethod.POST) + @RequestMapping(value = "/{application}/{pipelineNameOrId:.+}", method = RequestMethod.POST) HttpEntity invokePipelineConfig(@PathVariable("application") String application, - @PathVariable("pipelineName") String pipelineName, + @PathVariable("pipelineNameOrId") String pipelineNameOrId, @RequestBody(required = false) Map trigger) { trigger = trigger ?: [:] trigger.user = trigger.user ?: AuthenticatedRequest.getSpinnakerUser().orElse('anonymous') try { - def body = pipelineService.trigger(application, pipelineName, trigger) + def body = pipelineService.trigger(application, pipelineNameOrId, trigger) new ResponseEntity(body, HttpStatus.ACCEPTED) } catch (PipelineConfigNotFoundException e) { throw e } catch (e) { - log.error("Unable to trigger pipeline (application: ${application}, pipelineName: ${pipelineName})", e) + log.error("Unable to trigger pipeline (application: ${application}, pipelineName: ${pipelineNameOrId})", e) new ResponseEntity([message: e.message], new HttpHeaders(), HttpStatus.UNPROCESSABLE_ENTITY) } } diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ApplicationService.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ApplicationService.groovy index fef817a1b3..5bc814812e 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ApplicationService.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/ApplicationService.groovy @@ -135,9 +135,9 @@ class ApplicationService { } execute() } - Map getPipelineConfigForApplication(String app, String pipelineName) { + Map getPipelineConfigForApplication(String app, String pipelineNameOrId) { HystrixFactory.newMapCommand(GROUP, "getPipelineConfig") { - front50Service.getPipelineConfigsForApplication(app).find { it.name == pipelineName } + front50Service.getPipelineConfigsForApplication(app).find { it.name == pipelineNameOrId || it.id == pipelineNameOrId } } execute() } diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy index 35b46fdafc..f30e0ebf23 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy @@ -56,8 +56,8 @@ class PipelineService { front50Service.movePipelineConfig(moveCommand) } - Map trigger(String application, String pipelineName, Map trigger) { - def pipelineConfig = applicationService.getPipelineConfigForApplication(application, pipelineName) + Map trigger(String application, String pipelineNameOrId, Map trigger) { + def pipelineConfig = applicationService.getPipelineConfigForApplication(application, pipelineNameOrId) if (!pipelineConfig) { throw new PipelineConfigNotFoundException() } diff --git a/gate-web/src/test/groovy/com/netflix/spinnaker/gate/ApplicationServiceSpec.groovy b/gate-web/src/test/groovy/com/netflix/spinnaker/gate/ApplicationServiceSpec.groovy index 2a0317e864..e6ca085a0f 100644 --- a/gate-web/src/test/groovy/com/netflix/spinnaker/gate/ApplicationServiceSpec.groovy +++ b/gate-web/src/test/groovy/com/netflix/spinnaker/gate/ApplicationServiceSpec.groovy @@ -230,4 +230,34 @@ class ApplicationServiceSpec extends Specification { "prod" | "test" || "prod,test" null | null || "" } + + @Unroll + void "should return pipeline config based on name or id"() { + given: + HystrixRequestContext.initializeContext() + + def service = new ApplicationService() + def front50 = Mock(Front50Service) + def clouddriver = Mock(ClouddriverService) + def config = new ServiceConfiguration(services: [front50: new Service()]) + + service.serviceConfiguration = config + service.front50Service = front50 + service.clouddriverService = clouddriver + service.executorService = Executors.newFixedThreadPool(1) + def app = "theApp" + + when: + def result = service.getPipelineConfigForApplication(app, nameOrId) != null + + then: + result == expected + 1 * front50.getPipelineConfigsForApplication(app) >> [ [ id: "by-id", name: "by-name" ] ] + + where: + nameOrId || expected + "by-id" || true + "by-name" || true + "not-id" || false + } }