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(pipelineTriggers): change buildNumber type from int to string #1213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUPER minor, but what about adding a test for a non-numeric build number as well as a numeric build number? :P And maybe a call out/comment on why? I like this overall though!

def res = new BuildEvent()
res.content = new BuildEvent.Content(new BuildEvent.Project("job", build), "master")
res.details = new Metadata([type: BuildEvent.TYPE])
Expand Down