Skip to content
Permalink
Browse files
[FIXED JENKINS-11609] improve the robustness of the resolve()
  • Loading branch information
kohsuke committed Nov 4, 2011
1 parent 6440afd commit a233b958552269ab1d7b23be2be618c9ee812301
@@ -44,10 +44,13 @@ public Promotion(PromotionProcess project, File buildDir) throws IOException {

/**
* Gets the build that this promotion promoted.
*
* @return
* null if there's no such object. For example, if the build has already garbage collected.
*/
public AbstractBuild<?,?> getTarget() {
PromotionTargetAction pta = getAction(PromotionTargetAction.class);
return pta.resolve();
return pta.resolve(this);
}

public AbstractBuild<?,?> getRootBuild() {
@@ -340,7 +340,7 @@ public Future<Promotion> scheduleBuild2(AbstractBuild<?,?> build, Cause cause) {

public boolean isInQueue(AbstractBuild<?,?> build) {
for (Item item : Hudson.getInstance().getQueue().getItems(this))
if (item.getAction(PromotionTargetAction.class).resolve()==build)
if (item.getAction(PromotionTargetAction.class).resolve(this)==build)
return true;
return false;
}
@@ -6,7 +6,7 @@
import hudson.model.InvisibleAction;

/**
* Remembers what build it's promoting.
* Remembers what build it's promoting. Attached to {@link Promotion}.
*
* @author Kohsuke Kawaguchi
*/
@@ -24,4 +24,14 @@ public AbstractBuild<?,?> resolve() {
if (j==null) return null;
return j.getBuildByNumber(number);
}

public AbstractBuild<?,?> resolve(PromotionProcess parent) {
AbstractProject<?,?> j = parent.getOwner();
if (j==null) return null;
return j.getBuildByNumber(number);
}

public AbstractBuild<?,?> resolve(Promotion parent) {
return resolve(parent.getParent());
}
}
@@ -0,0 +1,42 @@
package hudson.plugins.promoted_builds;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParameterValue;
import hudson.plugins.promoted_builds.conditions.ManualCondition;
import hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval;
import org.jvnet.hudson.test.HudsonTestCase;

import java.util.Collections;

/**
* @author Kohsuke Kawaguchi
*/
public class PromotionTargetActionTest extends HudsonTestCase {
/**
* When a project is created, built, and renamed, then the old build is created,
* that results in NPE.
*/
public void test1() throws Exception {
FreeStyleProject up = createFreeStyleProject("up");
up.setCustomWorkspace(createTmpDir().getPath());

// promote if the downstream passes
JobPropertyImpl promotion = new JobPropertyImpl(up);
up.addProperty(promotion);
PromotionProcess proc = promotion.addProcess("promo");
proc.conditions.add(new ManualCondition());

FreeStyleBuild b = assertBuildStatusSuccess(up.scheduleBuild2(0));

b.addAction(new ManualApproval(proc.getName(), Collections.<ParameterValue>emptyList()));
b.save();

// check for promotion
Promotion p = assertBuildStatusSuccess(proc.considerPromotion2(b));

up.renameTo("up2");

assertSame(b,p.getTarget());
}
}

0 comments on commit a233b95

Please sign in to comment.