Skip to content

Commit

Permalink
Merge pull request #160 from julieheard/abortPreviousBuild
Browse files Browse the repository at this point in the history
Fix incorrect abort cause
  • Loading branch information
jglick authored Apr 17, 2024
2 parents b07d21d + f3f31d7 commit fe78bdc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,18 @@ public boolean start() throws Exception {

@Override
public void stop(Throwable cause) throws Exception {
outcome = new Outcome(null,cause);
// JENKINS-37154: we might be inside the VM thread, so do not do anything which might block on the VM thread
Timer.get().submit(new Runnable() {
@Override public void run() {
try (ACLContext context = ACL.as(ACL.SYSTEM)) {
doAbort();
postSettlement();
} catch (IOException | InterruptedException x) {
LOGGER.log(Level.WARNING, "failed to abort " + getContext(), x);
}
}
});
super.stop(cause);
}

@Exported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -397,6 +398,28 @@ private void runAndContinue(JenkinsRule.WebClient webClient, WorkflowJob foo, St
}
}

@Test
public void abortPreviousBuilds() throws Exception {
//Create a new job and set the AbortPreviousBuildsJobProperty
WorkflowJob job = j.createProject(WorkflowJob.class, "myJob");
job.setDefinition(new CpsFlowDefinition("input 'proceed?'", true));
DisableConcurrentBuildsJobProperty jobProperty = new DisableConcurrentBuildsJobProperty();
jobProperty.setAbortPrevious(true);
job.addProperty(jobProperty);
job.save();

//Run the job and wait for the input step
WorkflowRun run1 = job.scheduleBuild2(0).waitForStart();
j.waitForMessage("proceed", run1);

//run another job and wait for the input step
WorkflowRun run2 = job.scheduleBuild2(0).waitForStart();
j.waitForMessage("proceed", run2);

//check that the first job has been aborted with the result of NOT_BUILT
j.assertBuildStatus(Result.NOT_BUILT, j.waitForCompletion(run1));
}

@Issue("JENKINS-38380")
@Test public void timeoutAuth() throws Exception {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
Expand Down

0 comments on commit fe78bdc

Please sign in to comment.