Skip to content

Commit

Permalink
[FIXED JENKINS-15160] Earliest git hash passed by parameter trigger.
Browse files Browse the repository at this point in the history
Correction is to create a seperate build for each git hash rather than
allowing them to be combined into a single build.
  • Loading branch information
cjo9900 committed Oct 23, 2012
1 parent 600e59e commit 0d21dcc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
34 changes: 32 additions & 2 deletions src/main/java/hudson/plugins/git/RevisionParameterAction.java
Expand Up @@ -23,18 +23,24 @@
*/
package hudson.plugins.git;

import hudson.model.Action;
import hudson.model.InvisibleAction;
import org.eclipse.jgit.lib.ObjectId;
import hudson.model.Queue.QueueAction;
import hudson.Util;

import org.eclipse.jgit.lib.ObjectId;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Logger;


/**
* Used as a build parameter to specify the revision to be built.
*
* @author Kohsuke Kawaguchi
* @author Chris Johnson
*/
public class RevisionParameterAction extends InvisibleAction implements Serializable {
public class RevisionParameterAction extends InvisibleAction implements Serializable,QueueAction {
/**
* SHA1, ref name, etc. that can be "git rev-parse"d into a specific commit.
*/
Expand All @@ -57,6 +63,30 @@ public String toString() {
return super.toString()+"[commit="+commit+"]";
}

/**
* Returns whether the new item should be scheduled.
* An action should return true if the associated task is 'different enough' to warrant a separate execution.
* from {@link #QueueAction}
*/
public boolean shouldSchedule(List<Action> actions) {
/* Called in two cases
1. On the action attached to an existing queued item
2. On the action attached to the new item to add.
Behaviour
If actions contain a RevisionParameterAction with a matching commit to this one, we do not need to schedule
in all other cases we do.
*/
List<RevisionParameterAction> otherActions = Util.filter(actions,RevisionParameterAction.class);

for (RevisionParameterAction action: otherActions) {
if(this.commit.equals(action.commit))
return false;
}

// if we get to this point there were no matching actions so a new build is required
return true;
}

private static final long serialVersionUID = 1L;
private static final Logger LOGGER = Logger.getLogger(RevisionParameterAction.class.getName());
}
Expand Down
40 changes: 36 additions & 4 deletions src/test/java/hudson/plugins/git/RevisionParameterActionTest.java
Expand Up @@ -37,8 +37,8 @@
public class RevisionParameterActionTest extends HudsonTestCase {

/**
* Test covering the behaviour until 1.1.25 where passing different revision
* actions to a job in the queue combines them and ignores the later revisions.
* Test covering the behaviour after 1.1.26 where passing different revision
* actions to a job in the queue creates seperate builds
*/
public void testCombiningScheduling() throws Exception {

Expand All @@ -48,9 +48,24 @@ public void testCombiningScheduling() throws Exception {
Future b1 = fs.scheduleBuild2(20, null, Collections.singletonList(new RevisionParameterAction("DEADBEEF")));
Future b2 = fs.scheduleBuild2(20, null, Collections.singletonList(new RevisionParameterAction("FREED456")));

//System.out.println(b1);
//System.out.println(b2);
// Check that we have the correct futures.
assertNotNull(b1);
assertNotNull(b2);

// Check that only one build occured
waitUntilNoActivity();
assertEquals(fs.getBuilds().size(),2);
}
/** test when existing revision is already in the queue
*/
public void testCombiningScheduling2() throws Exception {

FreeStyleProject fs = createFreeStyleProject("freestyle");

// scheduleBuild2 returns null if request is combined into an existing item. (no new item added to queue)
Future b1 = fs.scheduleBuild2(20, null, Collections.singletonList(new RevisionParameterAction("DEADBEEF")));
Future b2 = fs.scheduleBuild2(20, null, Collections.singletonList(new RevisionParameterAction("DEADBEEF")));

// Check that we have the correct futures.
assertNotNull(b1);
assertNull(b2);
Expand All @@ -59,5 +74,22 @@ public void testCombiningScheduling() throws Exception {
waitUntilNoActivity();
assertEquals(fs.getBuilds().size(),1);
}
/** test when there is no revision on the item in the queue
*/
public void testCombiningScheduling3() throws Exception {

FreeStyleProject fs = createFreeStyleProject("freestyle");

// scheduleBuild2 returns null if request is combined into an existing item. (no new item added to queue)
Future b1 = fs.scheduleBuild2(20);
Future b2 = fs.scheduleBuild2(20, null, Collections.singletonList(new RevisionParameterAction("DEADBEEF")));

// Check that we have the correct futures.
assertNotNull(b1);
assertNotNull(b2);

// Check that only one build occured
waitUntilNoActivity();
assertEquals(fs.getBuilds().size(),2);
}
}

0 comments on commit 0d21dcc

Please sign in to comment.