From 04ca93bdf93873053d31598c18cc32afaf765d26 Mon Sep 17 00:00:00 2001 From: Raul Cristian <24556350+ciurescuraul@users.noreply.github.com> Date: Fri, 22 Dec 2023 18:59:22 +0200 Subject: [PATCH] feat(jenkins): Enable Jenkins job triggers for jobs in sub-folders (#4618) * feat(jenkins): Enable Jenkins job triggers for jobs in sub-folders - 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). * feat(jenkins): initiate flag to false in tests (cherry picked from commit 13c6f6ebffac383124fda7a838180d9fed97d4de) # Conflicts: # orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java --- .../spinnaker/orca/igor/BuildService.java | 22 +++++++++---------- .../orca/igor/IgorFeatureFlagProperties.java | 8 +++++++ .../spinnaker/orca/igor/IgorService.java | 6 +++++ .../orca/igor/BuildServiceSpec.groovy | 14 +++++++++++- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/BuildService.java b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/BuildService.java index 0ecc8a0d82..4afa1ffc34 100644 --- a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/BuildService.java +++ b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/BuildService.java @@ -18,19 +18,17 @@ import com.netflix.spinnaker.kork.artifacts.model.Artifact; import java.util.List; import java.util.Map; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.web.util.UriUtils; import retrofit.client.Response; +@RequiredArgsConstructor +@EnableConfigurationProperties(IgorFeatureFlagProperties.class) public class BuildService { private final IgorService igorService; private final IgorFeatureFlagProperties igorFeatureFlagProperties; - public BuildService( - IgorService igorService, IgorFeatureFlagProperties igorFeatureFlagProperties) { - this.igorService = igorService; - this.igorFeatureFlagProperties = igorFeatureFlagProperties; - } - private String encode(String uri) { return UriUtils.encodeFragment(uri, "UTF-8"); } @@ -45,11 +43,9 @@ public Response build( } public String stop(String master, String jobName, String queuedBuild, Integer buildNumber) { - if (this.igorFeatureFlagProperties.isJobNameAsQueryParameter()) { - return igorService.stopWithJobNameAsQueryParameter( - master, jobName, queuedBuild, buildNumber, ""); - } - return igorService.stop(master, jobName, queuedBuild, buildNumber, ""); + return this.igorFeatureFlagProperties.isJobNameAsQueryParameter() + ? igorService.stopWithJobNameAsQueryParameter(master, jobName, queuedBuild, buildNumber, "") + : igorService.stop(master, jobName, queuedBuild, buildNumber, ""); } public Map queuedBuild(String master, String item) { @@ -57,7 +53,9 @@ public Map queuedBuild(String master, String item) { } public Map getBuild(Integer buildNumber, String master, String job) { - return igorService.getBuild(buildNumber, master, encode(job)); + return this.igorFeatureFlagProperties.isJobNameAsQueryParameter() + ? igorService.getBuildWithJobAsQueryParam(buildNumber, master, encode(job)) + : igorService.getBuild(buildNumber, master, encode(job)); } public Map getPropertyFile( diff --git a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java index dde970a583..008ad18097 100644 --- a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java +++ b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java @@ -16,10 +16,15 @@ package com.netflix.spinnaker.orca.igor; +import lombok.Getter; +import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; +@Getter +@Setter @ConfigurationProperties(prefix = "feature.igor") public class IgorFeatureFlagProperties { +<<<<<<< HEAD private boolean jobNameAsQueryParameter = false; public boolean isJobNameAsQueryParameter() { @@ -29,4 +34,7 @@ public boolean isJobNameAsQueryParameter() { public void setJobNameAsQueryParameter(boolean jobNameAsQueryParameter) { this.jobNameAsQueryParameter = jobNameAsQueryParameter; } +======= + private boolean jobNameAsQueryParameter = true; +>>>>>>> 13c6f6ebf (feat(jenkins): Enable Jenkins job triggers for jobs in sub-folders (#4618)) } diff --git a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorService.java b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorService.java index b9896c678b..e2ec1a5c68 100644 --- a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorService.java +++ b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorService.java @@ -66,6 +66,12 @@ Map getBuild( @Path("master") String master, @Path(encode = false, value = "job") String job); + @GET("/builds/status/{buildNumber}/{master}") + Map getBuildWithJobAsQueryParam( + @Path("buildNumber") Integer buildNumber, + @Path("master") String master, + @Query(encodeValue = false, value = "job") String job); + @GET("/builds/properties/{buildNumber}/{fileName}/{master}/{job}") Map getPropertyFile( @Path("buildNumber") Integer buildNumber, diff --git a/orca-igor/src/test/groovy/com/netflix/spinnaker/orca/igor/BuildServiceSpec.groovy b/orca-igor/src/test/groovy/com/netflix/spinnaker/orca/igor/BuildServiceSpec.groovy index 16c097f33a..9577b5b5ba 100644 --- a/orca-igor/src/test/groovy/com/netflix/spinnaker/orca/igor/BuildServiceSpec.groovy +++ b/orca-igor/src/test/groovy/com/netflix/spinnaker/orca/igor/BuildServiceSpec.groovy @@ -33,7 +33,7 @@ class BuildServiceSpec extends Specification { void setup() { igorService = Mock(IgorService) - buildService = new BuildService(igorService, new IgorFeatureFlagProperties()) + buildService = new BuildService(igorService, new IgorFeatureFlagProperties(jobNameAsQueryParameter: false)) } void 'build method encodes the job name'() { @@ -52,6 +52,18 @@ class BuildServiceSpec extends Specification { 1 * igorService.getBuild(BUILD_NUMBER, MASTER, JOB_NAME_ENCODED) } + void 'getBuild method get job name in query when flag is true'() { + IgorFeatureFlagProperties igorFeatureFlagProperties = new IgorFeatureFlagProperties() + igorFeatureFlagProperties.setJobNameAsQueryParameter(true) + buildService = new BuildService(igorService, igorFeatureFlagProperties) + + when: + buildService.getBuild(BUILD_NUMBER, MASTER, JOB_NAME) + + then: + 1 * igorService.getBuildWithJobAsQueryParam(BUILD_NUMBER, MASTER, JOB_NAME_ENCODED) + } + void 'getPropertyFile method encodes the job name'() { when: buildService.getPropertyFile(BUILD_NUMBER, FILENAME, MASTER, JOB_NAME)