Skip to content

Commit

Permalink
Fix detection of next build number
Browse files Browse the repository at this point in the history
If many multiple jobs are starting at the same time, it is not safe to
query next build number and then launch the job. Instead, pick up the
build number from the POST response directly.
  • Loading branch information
scottanderson committed Oct 29, 2014
1 parent a2360de commit 3df490b
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,25 +525,17 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
String queryUrlString = this.buildGetUrl(jobName, securityToken);
queryUrlString += "/api/json/";

//listener.getLogger().println("Getting ID of next job to build. URL: " + queryUrlString);
JSONObject queryResponseObject = sendHTTPCall(queryUrlString, "GET", build, listener);
if (queryResponseObject == null ) {
//This should not happen as this page should return a JSON object
this.failBuild(new Exception("Got a blank response from Remote Jenkins Server [" + remoteServerURL + "], cannot continue."), listener);
}

int nextBuildNumber = queryResponseObject.getInt("nextBuildNumber");
listener.getLogger().println("This job is build #[" + Integer.toString(nextBuildNumber) + "] on the remote server.");

if (this.getOverrideAuth()) {
listener.getLogger().println(
"Using job-level defined credentails in place of those from remote Jenkins config ["
+ this.getRemoteJenkinsName() + "]");
}

listener.getLogger().println("Triggering remote job now.");
sendHTTPCall(triggerUrlString, "POST", build, listener);

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.");

//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

0 comments on commit 3df490b

Please sign in to comment.