Skip to content

Commit

Permalink
Store triggered build environment variables
Browse files Browse the repository at this point in the history
Save TRIGGERED_BUILD_NUMBER and, if blocking, TRIGGERED_BUILD_RESULT to
the build environment. Prior to this change, it was necessary to parse
the log file, which was very hacky and only possible on the master. This
can be used by later build steps and downstream jobs.
  • Loading branch information
scottanderson committed Oct 29, 2014
1 parent 3df490b commit a294e57
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
JSONObject queryResponseObject = sendHTTPCall(triggerUrlString, "POST", build, listener);
int nextBuildNumber = queryResponseObject.getInt("nextBuildNumber");
listener.getLogger().println("This job is build #[" + Integer.toString(nextBuildNumber) + "] on the remote server.");
build.getEnvironment(listener).put("TRIGGERED_BUILD_NUMBER", Integer.toString(nextBuildNumber));

//Have to form the string ourselves, as we might not get a response from non-parameterized builds
String jobURL = remoteServerURL + "/job/" + this.encodeValue(job) + "/";
Expand Down Expand Up @@ -594,6 +595,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
}
}
listener.getLogger().println("Remote build finished with status " + buildStatusStr + ".");
build.getEnvironment(listener).put("TRIGGERED_BUILD_RESULT", Integer.toString(nextBuildNumber));

// If build did not finish with 'success' then fail build step.
if (!buildStatusStr.equals("SUCCESS")) {
Expand Down

0 comments on commit a294e57

Please sign in to comment.