Skip to content

Commit

Permalink
Merge pull request #4 from patbos/JENKINS-20065
Browse files Browse the repository at this point in the history
JENKINS-20065 Retain original build causes
  • Loading branch information
ndeloof committed Mar 26, 2014
2 parents bb3bb9f + c54ee58 commit 2bd688a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Expand Up @@ -90,7 +90,8 @@ public boolean canSchedule(Run build, NaginatorPublisher naginator) {
*/
public boolean scheduleBuild(AbstractBuild<?, ?> build, int n) {
ParametersAction p = build.getAction(ParametersAction.class);
return build.getProject().scheduleBuild(n, new NaginatorCause(), p, new NaginatorAction());
CauseAction causeAction = new CauseAction(build.getAction(CauseAction.class));
return build.getProject().scheduleBuild(n, new NaginatorCause(), p, new NaginatorAction(), causeAction);
}

private boolean parseLog(File logFile, String regexp) throws IOException {
Expand Down
Expand Up @@ -2,14 +2,17 @@

import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
import hudson.model.*;
import hudson.tasks.BuildTrigger;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import hudson.tasks.Builder;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.jvnet.hudson.test.HudsonTestCase;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -104,6 +107,40 @@ public void testWithBuildWrapper() throws Exception {
assertEquals(true, isScheduledForRetry(project));
}

/**
* A -> B
*
* A triggers B if successful.
* B will be rebuild 2 times if it fails and it will.
*
* Test will check that B:s rebuild attempts will also contain the UpstreamCause from the original B:s build
*
* @throws Exception
*/
public void testRetainCauses() throws Exception {
FreeStyleProject a = createFreeStyleProject("a");
FreeStyleProject b = createFreeStyleProject("b");
a.getPublishersList().add(new BuildTrigger("b", Result.SUCCESS));
NaginatorPublisher nag = new NaginatorPublisher("", false, false, 2, new FixedDelay(1));

b.getPublishersList().add(nag);

BuildWrapper failTheBuild = new FailTheBuild();
b.getBuildWrappersList().add(failTheBuild);
jenkins.rebuildDependencyGraph();

buildAndAssertSuccess(a);
waitUntilNoActivity();
assertNotNull(a.getLastBuild());
assertNotNull(b.getLastBuild());
assertEquals(1, a.getLastBuild().getNumber());
assertEquals(3, b.getLastBuild().getNumber());
assertEquals(Result.FAILURE, b.getLastBuild().getResult());
assertEquals(2, b.getBuildByNumber(2).getActions(CauseAction.class).size());
assertEquals(2, b.getBuildByNumber(3).getActions(CauseAction.class).size());

}


private boolean isScheduledForRetry(String buildLog, Result result, String regexpForRerun,
boolean rerunIfUnstable, boolean checkRegexp) throws Exception {
Expand Down

0 comments on commit 2bd688a

Please sign in to comment.