From 3df490b36b52c32c9f93a0fac82061ed56858285 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Wed, 29 Oct 2014 19:28:57 -0400 Subject: [PATCH] Fix detection of next build number 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. --- .../RemoteBuildConfiguration.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration.java b/src/main/java/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration.java index 99e3c6c3..fd4b9e24 100644 --- a/src/main/java/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration.java +++ b/src/main/java/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration.java @@ -525,16 +525,6 @@ 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 [" @@ -542,8 +532,10 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis } 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) + "/";