Skip to content

Commit

Permalink
[FIXED JENKINS-28673] ISE after deleting a downstream build.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed May 18, 2016
1 parent a850c28 commit c869245
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Expand Up @@ -7,6 +7,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.listeners.RunListener;
import java.util.List;
import org.jenkinsci.plugins.workflow.steps.StepContext;

import java.util.logging.Logger;
Expand Down Expand Up @@ -37,14 +38,17 @@ public void onStarted(Run<?, ?> run, TaskListener listener) {
}

@Override
@SuppressWarnings("deprecation") // TODO Actionable offers no standard way of removing actions
public void onCompleted(Run<?,?> run, @Nonnull TaskListener listener) {
for (BuildTriggerAction action : run.getActions(BuildTriggerAction.class)) {
List<BuildTriggerAction> actions = run.getActions(BuildTriggerAction.class);
for (BuildTriggerAction action : actions) {
if (!action.isPropagate() || run.getResult() == Result.SUCCESS) {
action.getStepContext().onSuccess(new RunWrapper(run, false));
} else {
action.getStepContext().onFailure(new AbortException(run.getFullDisplayName() + " completed with status " + run.getResult() + " (propagate: false to ignore)"));
}
}
run.getActions().removeAll(actions);
}

@Override
Expand Down
Expand Up @@ -69,9 +69,15 @@ public void evaluate() throws Throwable {
WorkflowRun r2 = foo.getLastBuild();
assertNotNull(r2);
story.j.assertBuildStatusSuccess(r2);
}
}
);
}
});

story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
story.j.jenkins.getItemByFullName("test1", FreeStyleProject.class).getBuildByNumber(1).delete();
}
});
}

private void assertFreeStyleProjectsInQueue(int count) {
Expand Down
Expand Up @@ -39,12 +39,15 @@ public class BuildTriggerStepTest {

@Issue("JENKINS-25851")
@Test public void buildTopLevelProject() throws Exception {
j.createFreeStyleProject("ds");
FreeStyleProject ds = j.createFreeStyleProject("ds");
WorkflowJob us = j.jenkins.createProject(WorkflowJob.class, "us");
us.setDefinition(new CpsFlowDefinition(
"def ds = build 'ds'\n" +
"echo \"ds.result=${ds.result} ds.number=${ds.number}\"", true));
j.assertLogContains("ds.result=SUCCESS ds.number=1", j.assertBuildStatusSuccess(us.scheduleBuild2(0)));
// TODO JENKINS-28673 assert no warnings, as in StartupTest.noWarnings
// (but first need to deal with `WARNING: Failed to instantiate optional component org.jenkinsci.plugins.workflow.steps.scm.SubversionStep$DescriptorImpl; skipping`)
ds.getBuildByNumber(1).delete();
}

@Issue("JENKINS-25851")
Expand Down Expand Up @@ -254,10 +257,12 @@ public void cancelBuildQueue() throws Exception {

@Issue("JENKINS-29169")
@Test public void buildVariablesWorkflow() throws Exception {
j.jenkins.createProject(WorkflowJob.class, "ds").setDefinition(new CpsFlowDefinition("env.RESULT = \"ds-${env.BUILD_NUMBER}\"", true));
WorkflowJob ds = j.jenkins.createProject(WorkflowJob.class, "ds");
ds.setDefinition(new CpsFlowDefinition("env.RESULT = \"ds-${env.BUILD_NUMBER}\"", true));
WorkflowJob us = j.jenkins.createProject(WorkflowJob.class, "us");
us.setDefinition(new CpsFlowDefinition("def vars = build('ds').buildVariables; echo \"received RESULT=${vars.RESULT} vs. BUILD_NUMBER=${vars.BUILD_NUMBER}\"", true));
j.assertLogContains("received RESULT=ds-1 vs. BUILD_NUMBER=null", j.assertBuildStatusSuccess(us.scheduleBuild2(0)));
ds.getBuildByNumber(1).delete();
}

@Issue("JENKINS-28063")
Expand Down

0 comments on commit c869245

Please sign in to comment.