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
…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 13c6f6e)
  • Loading branch information
ciurescuraul authored and mergify[bot] committed Jan 22, 2024
1 parent 4740c16 commit 02de3c5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -45,19 +43,19 @@ 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) {
return igorService.queuedBuild(master, item);
}

public Map<String, Object> 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<String, Object> getPropertyFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@

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 {
private boolean jobNameAsQueryParameter = true;

public boolean isJobNameAsQueryParameter() {
return jobNameAsQueryParameter;
}

public void setJobNameAsQueryParameter(boolean jobNameAsQueryParameter) {
this.jobNameAsQueryParameter = jobNameAsQueryParameter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ Map<String, Object> getBuild(
@Path("master") String master,
@Path(encode = false, value = "job") String job);

@GET("/builds/status/{buildNumber}/{master}")
Map<String, Object> getBuildWithJobAsQueryParam(
@Path("buildNumber") Integer buildNumber,
@Path("master") String master,
@Query(encodeValue = false, value = "job") String job);

@GET("/builds/properties/{buildNumber}/{fileName}/{master}/{job}")
Map<String, Object> getPropertyFile(
@Path("buildNumber") Integer buildNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'() {
Expand All @@ -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)
Expand Down

0 comments on commit 02de3c5

Please sign in to comment.