From abce0915d190fc831b971987b969deb1a19774d2 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 15:30:26 +0000 Subject: [PATCH] fix(jenkins): Enable properties and artifacts with job name as query parameter (#1393) (#1395) Co-authored-by: Jason (cherry picked from commit 44317c1f73cc0701ab8cc1e648a7cfe16e3dd9ca) Co-authored-by: Christos Arvanitis --- .../echo/build/BuildInfoService.java | 14 +++++++++-- .../spinnaker/echo/services/IgorService.java | 14 +++++++++++ .../BuildEventHandlerSpec.groovy | 24 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/echo-core/src/main/java/com/netflix/spinnaker/echo/build/BuildInfoService.java b/echo-core/src/main/java/com/netflix/spinnaker/echo/build/BuildInfoService.java index 056bdccee..63452df9b 100644 --- a/echo-core/src/main/java/com/netflix/spinnaker/echo/build/BuildInfoService.java +++ b/echo-core/src/main/java/com/netflix/spinnaker/echo/build/BuildInfoService.java @@ -93,7 +93,12 @@ public Map getProperties(BuildEvent event, String propertyFile) } String propertyFileFinal = propertyFile; if (StringUtils.isNoneEmpty(master, job, propertyFile)) { - return retry(() -> igorService.getPropertyFile(buildNumber, propertyFileFinal, master, job)); + return retry( + () -> + igorConfigurationProperties.isJobNameAsQueryParameter() + ? igorService.getPropertyFileWithJobQueryParameter( + buildNumber, propertyFileFinal, master, job) + : igorService.getPropertyFile(buildNumber, propertyFileFinal, master, job)); } return Collections.emptyMap(); } @@ -103,7 +108,12 @@ private List getArtifactsFromPropertyFile(BuildEvent event, String pro String job = event.getContent().getProject().getName(); int buildNumber = event.getBuildNumber(); if (StringUtils.isNoneEmpty(master, job, propertyFile)) { - return retry(() -> igorService.getArtifacts(buildNumber, propertyFile, master, job)); + return retry( + () -> + igorConfigurationProperties.isJobNameAsQueryParameter() + ? igorService.getArtifactsWithJobQueryParameter( + buildNumber, propertyFile, master, job) + : igorService.getArtifacts(buildNumber, propertyFile, master, job)); } return Collections.emptyList(); } diff --git a/echo-core/src/main/java/com/netflix/spinnaker/echo/services/IgorService.java b/echo-core/src/main/java/com/netflix/spinnaker/echo/services/IgorService.java index 063428552..3936d22c7 100644 --- a/echo-core/src/main/java/com/netflix/spinnaker/echo/services/IgorService.java +++ b/echo-core/src/main/java/com/netflix/spinnaker/echo/services/IgorService.java @@ -44,6 +44,13 @@ Map getPropertyFile( @Path("master") String master, @Path(value = "job", encode = false) String job); + @GET("/builds/properties/{buildNumber}/{fileName}/{master}") + Map getPropertyFileWithJobQueryParameter( + @Path("buildNumber") Integer buildNumber, + @Path("fileName") String fileName, + @Path("master") String master, + @Query(value = "job") String job); + @GET("/builds/artifacts/{buildNumber}/{master}/{job}") List getArtifacts( @Path("buildNumber") Integer buildNumber, @@ -51,6 +58,13 @@ List getArtifacts( @Path("master") String master, @Path(value = "job", encode = false) String job); + @GET("/builds/artifacts/{buildNumber}/{master}") + List getArtifactsWithJobQueryParameter( + @Path("buildNumber") Integer buildNumber, + @Query("propertyFile") String propertyFile, + @Path("master") String master, + @Query(value = "job") String job); + @GET("/artifacts/{provider}/{packageName}") List getVersions( @Path("provider") String provider, @Path("packageName") String packageName); diff --git a/echo-pipelinetriggers/src/test/groovy/com/netflix/spinnaker/echo/pipelinetriggers/eventhandlers/BuildEventHandlerSpec.groovy b/echo-pipelinetriggers/src/test/groovy/com/netflix/spinnaker/echo/pipelinetriggers/eventhandlers/BuildEventHandlerSpec.groovy index c897c51f5..5d9d6dfc0 100644 --- a/echo-pipelinetriggers/src/test/groovy/com/netflix/spinnaker/echo/pipelinetriggers/eventhandlers/BuildEventHandlerSpec.groovy +++ b/echo-pipelinetriggers/src/test/groovy/com/netflix/spinnaker/echo/pipelinetriggers/eventhandlers/BuildEventHandlerSpec.groovy @@ -290,6 +290,30 @@ class BuildEventHandlerSpec extends Specification implements RetrofitStubs { outputTrigger.properties.equals(PROPERTIES) } + def "fetches fetches property file if defined with job name from query when flag is true"() { + given: + def mockProperties = PROPERTIES + def trigger = enabledJenkinsTrigger.withMaster(MASTER_NAME).withBuildNumber(BUILD_NUMBER).withPropertyFile(PROPERTY_FILE) + createPipelineWith(enabledJenkinsTrigger).withTrigger(trigger) + def event = getBuildEvent() + + def retrySupport = new RetrySupport() + def configProperties = new IgorConfigurationProperties(jobNameAsQueryParameter: true) + def buildInfoService = new BuildInfoService(igorService, retrySupport, configProperties) + + def permissionEvaluator = fiatPermissionEvaluator + def buildEventHandler = new BuildEventHandler(registry, objectMapper, Optional.of(buildInfoService), permissionEvaluator) + + when: + def outputTrigger = buildEventHandler.buildTrigger(event).apply(trigger) + + then: + 1 * igorService.getBuildStatusWithJobQueryParameter(BUILD_NUMBER, MASTER_NAME, JOB_NAME) >> BUILD_INFO + 1 * igorService.getPropertyFileWithJobQueryParameter(BUILD_NUMBER, PROPERTY_FILE, MASTER_NAME, JOB_NAME) >> mockProperties + outputTrigger.buildInfo == BUILD_INFO + outputTrigger.properties == mockProperties + } + def "checks constraints on property file if defined"() { given: def trigger = enabledJenkinsTrigger