Skip to content

Commit

Permalink
fix(jenkins): Enable properties and artifacts with job name as query …
Browse files Browse the repository at this point in the history
…parameter (#1393) (#1396)

Co-authored-by: Jason <[email protected]>
(cherry picked from commit 44317c1)

Co-authored-by: Christos Arvanitis <[email protected]>
  • Loading branch information
mergify[bot] and christosarvanitis authored Feb 27, 2024
1 parent f96eee3 commit d5ebde4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
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

0 comments on commit d5ebde4

Please sign in to comment.