Skip to content
Permalink
Browse files

[FIXED JENKINS-13546]

Bringing this to the parity with ParameterizedJobMixIn.doBuild()

Instead of returning JSON, it returns "201 Created" and responds with the location of the queue item, through which the caller can track how it passes through the queue and eventually gets built/cancelled.

The approach in pull request #750 that relies on
AbstractProject.getQueueItem() is inherently unreliable, because
item can be immediately built before the JSON is rendered, or it might
corresponds to other queued items if the build supports concurrent
builds, etc.
  • Loading branch information
kohsuke committed Apr 19, 2014
1 parent 5e9d59c commit 680dd4a21a575cebe37648b215b8f714848f6a15
Showing with 5 additions and 7 deletions.
  1. +5 −7 core/src/main/java/hudson/model/ParametersDefinitionProperty.java
@@ -122,7 +122,7 @@ public int size() {
/** @deprecated use {@link #_doBuild(StaplerRequest, StaplerResponse, TimeDuration)} */
@Deprecated
public void _doBuild(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
_doBuild(req,rsp,TimeDuration.fromString(req.getParameter("delay")));
_doBuild(req, rsp, TimeDuration.fromString(req.getParameter("delay")));
}

/**
@@ -179,14 +179,12 @@ public void buildWithParameters(StaplerRequest req, StaplerResponse rsp, @CheckF
}
if (delay==null) delay=new TimeDuration(getJob().getQuietPeriod());

Jenkins.getInstance().getQueue().schedule(
getJob(), delay.getTime(), new ParametersAction(values), ParameterizedJobMixIn.getBuildCause(getJob(), req));
Queue.Item item = Jenkins.getInstance().getQueue().schedule2(
getJob(), delay.getTime(), new ParametersAction(values), ParameterizedJobMixIn.getBuildCause(getJob(), req)).getItem();

if (requestWantsJson(req)) {

This comment has been minimized.

Copy link
@jglick

jglick Apr 24, 2014

Member

This method is now unused. Delete it?

rsp.setContentType("application/json");
rsp.serveExposedBean(req, owner, Flavor.JSON);
if (item != null) {
rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl());
} else {
// send the user back to the job top page.
rsp.sendRedirect(".");
}
}

0 comments on commit 680dd4a

Please sign in to comment.