Skip to content

Commit

Permalink
fix(pipelineTriggers): change buildNumber type from int to string
Browse files Browse the repository at this point in the history
in order to support build numbers which are not strict integers (i.e. "123.1")
  • Loading branch information
Jared Stehler authored and jaredstehler committed Feb 9, 2023
1 parent fa50e97 commit dba230c
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class BuildInfoService {
// to pass a trigger and
// an event as with other triggers, but for now we'll see whether we can extract a build event
// from the trigger.
public BuildEvent getBuildEvent(String master, String job, int buildNumber) {
public BuildEvent getBuildEvent(String master, String job, String buildNumber) {
Map<String, Object> rawBuild = retry(() -> igorService.getBuild(buildNumber, master, job));
BuildEvent.Build build = objectMapper.convertValue(rawBuild, BuildEvent.Build.class);
BuildEvent.Project project = new BuildEvent.Project(job, build);
Expand All @@ -61,7 +61,7 @@ public BuildEvent getBuildEvent(String master, String job, int buildNumber) {
public Map<String, Object> getBuildInfo(BuildEvent event) {
String master = event.getContent().getMaster();
String job = event.getContent().getProject().getName();
int buildNumber = event.getBuildNumber();
String buildNumber = event.getBuildNumber();

if (StringUtils.isNoneEmpty(master, job)) {
return retry(() -> igorService.getBuild(buildNumber, master, job));
Expand All @@ -72,7 +72,7 @@ public Map<String, Object> getBuildInfo(BuildEvent event) {
public Map<String, Object> getProperties(BuildEvent event, String propertyFile) {
String master = event.getContent().getMaster();
String job = event.getContent().getProject().getName();
int buildNumber = event.getBuildNumber();
String buildNumber = event.getBuildNumber();

if (StringUtils.isEmpty(propertyFile) && master.contains("travis")) {
propertyFile = "travis";
Expand All @@ -87,7 +87,7 @@ public Map<String, Object> getProperties(BuildEvent event, String propertyFile)
private List<Artifact> getArtifactsFromPropertyFile(BuildEvent event, String propertyFile) {
String master = event.getContent().getMaster();
String job = event.getContent().getProject().getName();
int buildNumber = event.getBuildNumber();
String buildNumber = event.getBuildNumber();
if (StringUtils.isNoneEmpty(master, job, propertyFile)) {
return retry(() -> igorService.getArtifacts(buildNumber, propertyFile, master, job));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
public interface IgorService {
@GET("/builds/status/{buildNumber}/{master}/{job}")
Map<String, Object> getBuild(
@Path("buildNumber") Integer buildNumber,
@Path("buildNumber") String buildNumber,
@Path("master") String master,
@Path(value = "job", encode = false) String job);

@GET("/builds/properties/{buildNumber}/{fileName}/{master}/{job}")
Map<String, Object> getPropertyFile(
@Path("buildNumber") Integer buildNumber,
@Path("buildNumber") String buildNumber,
@Path("fileName") String fileName,
@Path("master") String master,
@Path(value = "job", encode = false) String job);

@GET("/builds/artifacts/{buildNumber}/{master}/{job}")
List<Artifact> getArtifacts(
@Path("buildNumber") Integer buildNumber,
@Path("buildNumber") String buildNumber,
@Query("propertyFile") String propertyFile,
@Path("master") String master,
@Path(value = "job", encode = false) String job);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public String toString() {
String artifactName;

/** Properties that are bound at run-time */
Integer buildNumber;
String buildNumber;

String hash;
Map<String, Object> buildInfo;
Expand Down Expand Up @@ -217,7 +217,7 @@ public String generateFallbackId() {
return UUID.nameUUIDFromBytes(this.toString().getBytes()).toString();
}

public Trigger atBuildNumber(final int buildNumber) {
public Trigger atBuildNumber(final String buildNumber) {
return this.toBuilder().buildNumber(buildNumber).hash(null).tag(null).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static class Project {
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Build {
private boolean building;
private int number;
private String number;
private Result result;
private String url;
private List<Artifact> artifacts;
Expand All @@ -73,7 +73,7 @@ public enum Result {
}

@JsonIgnore
public int getBuildNumber() {
public String getBuildNumber() {
return content.getProject().getLastBuild().getNumber();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected Pipeline buildTrigger(Pipeline pipeline, Trigger manualTrigger) {
List<Artifact> artifacts = new ArrayList<>();
String master = manualTrigger.getMaster();
String job = manualTrigger.getJob();
Integer buildNumber = manualTrigger.getBuildNumber();
String buildNumber = manualTrigger.getBuildNumber();

ArrayList<String> pipelineErrors = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BuildEventHandlerSpec extends Specification implements RetrofitStubs {

String MASTER_NAME = "jenkins-server"
String JOB_NAME = "my-job"
int BUILD_NUMBER = 7
String BUILD_NUMBER = "7"
def PROPERTY_FILE = "property-file"
static Map<String, Object> BUILD_INFO = [
abc: 123
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExpectedArtifactExpressionEvaluationPostProcessorSpec extends Specificatio
.enabled(true).type('jenkins')
.master('master')
.job('job')
.buildNumber(100)
.buildNumber('100')
.build()

def 'evaluates expressions in expected artifacts'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ trait RetrofitStubs {
}

BuildEvent createBuildEventWith(BuildEvent.Result result) {
def build = result ? new BuildEvent.Build(result == BUILDING, 1, result, null, []) : null
def build = result ? new BuildEvent.Build(result == BUILDING, '1', result, null, []) : null
def res = new BuildEvent()
res.content = new BuildEvent.Content(new BuildEvent.Project("job", build), "master")
res.details = new Metadata([type: BuildEvent.TYPE])
Expand Down

0 comments on commit dba230c

Please sign in to comment.