未验证 提交 3a07a2c2 编写于 作者: J Jesse Glick 提交者: GitHub

Make `StopBuildsCommand` work even if the last build is not running (#7679)

上级 a1f732f2
......@@ -83,8 +83,10 @@ public class StopBuildsCommand extends CLICommand {
private void stopJobBuilds(final Job job) {
final Run lastBuild = job.getLastBuild();
final String jobName = job.getFullDisplayName();
if (lastBuild != null && lastBuild.isBuilding()) {
stopBuild(lastBuild, jobName);
if (lastBuild != null) {
if (lastBuild.isBuilding()) {
stopBuild(lastBuild, jobName);
}
checkAndStopPreviousBuilds(lastBuild, jobName);
}
}
......
......@@ -38,14 +38,19 @@ import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import jenkins.model.Jenkins;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.jvnet.hudson.test.SleepBuilder;
public class StopBuildsCommandTest {
@ClassRule
public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule
public JenkinsRule j = new JenkinsRule();
......@@ -177,6 +182,28 @@ public class StopBuildsCommandTest {
j.assertBuildStatus(Result.ABORTED, j.waitForCompletion(b2));
}
@Test
public void shouldStopEarlierBuildsEvenIfLatestComplete() throws Exception {
final FreeStyleProject project = createLongRunningProject(TEST_JOB_NAME);
project.setConcurrentBuild(true);
j.jenkins.setNumExecutors(3);
FreeStyleBuild b1 = project.scheduleBuild2(0).waitForStart();
j.waitForMessage("Sleeping", b1);
FreeStyleBuild b2 = project.scheduleBuild2(0).waitForStart();
j.waitForMessage("Sleeping", b2);
project.getBuildersList().clear();
FreeStyleBuild b3 = j.buildAndAssertSuccess(project);
final String stdout = runWith(List.of(TEST_JOB_NAME)).stdout();
assertThat(stdout, equalTo("Build '#2' stopped for job 'jobName'" + LN +
"Build '#1' stopped for job 'jobName'" + LN));
j.assertBuildStatus(Result.ABORTED, j.waitForCompletion(b1));
j.assertBuildStatus(Result.ABORTED, j.waitForCompletion(b2));
}
private CLICommandInvoker.Result runWith(final List<String> jobNames) throws Exception {
CLICommand cmd = new StopBuildsCommand();
CLICommandInvoker invoker = new CLICommandInvoker(j, cmd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册