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

fix(jenkins): Enable properties and artifacts with job name as query parameter (backport #1393) #1403

Merged
merged 1 commit into from
Mar 14, 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 @@ -93,7 +93,12 @@ public Map<String, Object> 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();
}
Expand All @@ -103,7 +108,12 @@ private List<Artifact> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ Map<String, Object> getPropertyFile(
@Path("master") String master,
@Path(value = "job", encode = false) String job);

@GET("/builds/properties/{buildNumber}/{fileName}/{master}")
Map<String, Object> 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<Artifact> getArtifacts(
@Path("buildNumber") Integer buildNumber,
@Query("propertyFile") String propertyFile,
@Path("master") String master,
@Path(value = "job", encode = false) String job);

@GET("/builds/artifacts/{buildNumber}/{master}")
List<Artifact> getArtifactsWithJobQueryParameter(
@Path("buildNumber") Integer buildNumber,
@Query("propertyFile") String propertyFile,
@Path("master") String master,
@Query(value = "job") String job);

@GET("/artifacts/{provider}/{packageName}")
List<String> getVersions(
@Path("provider") String provider, @Path("packageName") String packageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading