Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jenkins): Enable Jenkins job triggers for jobs in sub-folders (backport #4618) #4635

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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