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

[JENKINS-59656] check build id before interrupting from the executors widget #4264

Merged
merged 11 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 22 additions & 3 deletions core/src/main/java/hudson/model/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.acegisecurity.Authentication;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
Expand Down Expand Up @@ -835,21 +836,39 @@ public void start() {
@RequirePOST
@Deprecated
public void doStop( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
doStop().generateResponse(req,rsp,this);
doStop(req != null ? Util.fixEmpty(req.getParameter("what")) : null).generateResponse(req,rsp,this);
}

/**
* Stops the current build.
*
* @since 1.489
* @deprecated as of 2.???
* Use {@link #doStop(String)}.
*/
@RequirePOST
@Deprecated
public HttpResponse doStop() {
return doStop(null);
}

/**
* Stops the current build.
*
* @param what
* if not null, the externalizable id ({@link Run#getExternalizableId()})
* of the build the user expects to interrupt
* @since 2.???
*/
@RequirePOST
public HttpResponse doStop(@CheckForNull @QueryParameter(fixEmpty = true) String what) {
lock.writeLock().lock(); // need write lock as interrupt will change the field
try {
if (executable != null) {
getParentOf(executable).getOwnerTask().checkAbortPermission();
interrupt();
if (what == null || (executable instanceof Run && what.equals(((Run<?,?>) executable).getExternalizableId()))) {
getParentOf(executable).getOwnerTask().checkAbortPermission();
interrupt();
}
}
} finally {
lock.writeLock().unlock();
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/resources/lib/hudson/executors.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ THE SOFTWARE.
</st:include>
<td class="pane" align="center" valign="middle">
<j:if test="${e.hasStopPermission()}">
<l:stopButton href="${rootURL}/${c.url}${url}/stop" confirm="${%confirm(exe.fullDisplayName)}" alt="${%terminate this build}" />
<j:invokeStatic var="runId" className="java.net.URLEncoder" method="encode">
<j:arg value="${exe.externalizableId}" />
<j:arg value="UTF-8" />
</j:invokeStatic>
<l:stopButton href="${rootURL}/${c.url}${url}/stop?what=${runId}" confirm="${%confirm(exe.fullDisplayName)}" alt="${%terminate this build}" />
</j:if>
</td>
</j:otherwise>
Expand Down