-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-8590] added option for controlling the firing for
MatrixProject.
- Loading branch information
Showing
9 changed files
with
262 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/hudson/plugins/emailext/MatrixTriggerMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package hudson.plugins.emailext; | ||
|
||
import org.jvnet.localizer.Localizable; | ||
|
||
/** | ||
* Controls when the e-mail gets sent in case of the matrix project. | ||
*/ | ||
public enum MatrixTriggerMode { | ||
ONLY_PARENT(Messages._MatrixTriggerMode_OnlyParent(),true,false), | ||
ONLY_CONFIGURATIONS(Messages._MatrixTriggerMode_OnlyConfigurations(),false,true), | ||
BOTH(Messages._MatrixTriggerMode_Both(),true,true); // traditional default behaviour | ||
|
||
private final Localizable description; | ||
|
||
public final boolean forParent; | ||
public final boolean forChild; | ||
|
||
private MatrixTriggerMode(Localizable description, boolean forParent, boolean forChild) { | ||
this.description = description; | ||
this.forParent = forParent; | ||
this.forChild = forChild; | ||
} | ||
|
||
public String getDescription() { | ||
return description.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/help-matrixTriggerMode.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div> | ||
Specifies when to trigger a downstream build for matrix jobs: | ||
<ul> | ||
<li>ONLY_PARENT: trigger only once when parent finishes</li> | ||
<li>ONLY_CONFIGURATIONS: trigger for each configuration</li> | ||
<li>BOTH: combination of the 2 above options</li> | ||
</ul> | ||
|
||
Note: that downstream jobs will only be triggered, if they are not already in the build queue. | ||
So, if all your configurations finish within a short timeframe, only one downstream job | ||
might be triggered, even if you have selected ONLY_CONFIGURATIONS or BOTH. | ||
</div> |
6 changes: 5 additions & 1 deletion
6
src/main/resources/hudson/plugins/emailext/Messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
ExtendedEmailPublisherDescriptor.DisplayName=Editable Email Notification | ||
ExtendedEmailPublisherDescriptor.AdminAddress=address not configured yet <nobody> | ||
ExtendedEmailPublisherDescriptor.AdminAddress=address not configured yet <nobody> | ||
|
||
MatrixTriggerMode.OnlyParent=Trigger only the parent job | ||
MatrixTriggerMode.OnlyConfigurations=Trigger for each configuration | ||
MatrixTriggerMode.Both=Trigger for parent and each configuration |
116 changes: 116 additions & 0 deletions
116
src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherMatrixTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package hudson.plugins.emailext; | ||
|
||
import static org.junit.Assert.assertThat; | ||
import static org.junit.matchers.JUnitMatchers.hasItems; | ||
import hudson.matrix.Axis; | ||
import hudson.matrix.AxisList; | ||
import hudson.matrix.MatrixBuild; | ||
import hudson.matrix.MatrixProject; | ||
import hudson.model.labels.LabelAtom; | ||
import hudson.plugins.emailext.plugins.EmailTrigger; | ||
import hudson.plugins.emailext.plugins.trigger.PreBuildTrigger; | ||
import hudson.slaves.DumbSlave; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.jvnet.hudson.test.HudsonTestCase; | ||
import org.jvnet.mock_javamail.Mailbox; | ||
|
||
public class ExtendedEmailPublisherMatrixTest extends HudsonTestCase{ | ||
|
||
private ExtendedEmailPublisher publisher; | ||
private MatrixProject project; | ||
private List<DumbSlave> slaves; | ||
|
||
public void setUp() throws Exception{ | ||
super.setUp(); | ||
|
||
publisher = new ExtendedEmailPublisher(); | ||
publisher.defaultSubject = "%DEFAULT_SUBJECT"; | ||
publisher.defaultContent = "%DEFAULT_CONTENT"; | ||
|
||
project = createMatrixProject(); | ||
project.getPublishersList().add( publisher ); | ||
slaves = new ArrayList<DumbSlave>(); | ||
slaves.add(createOnlineSlave(new LabelAtom("success-slave1"))); | ||
slaves.add(createOnlineSlave(new LabelAtom("success-slave2"))); | ||
slaves.add(createOnlineSlave(new LabelAtom("success-slave3"))); | ||
|
||
|
||
|
||
//build. | ||
} | ||
|
||
public void tearDown() throws Exception | ||
{ | ||
super.tearDown(); | ||
slaves.clear(); | ||
Mailbox.clearAll(); | ||
} | ||
|
||
public void testPreBuildMatrixBuildSendParentOnly() throws Exception{ | ||
publisher.setMatrixTriggerMode(MatrixTriggerMode.ONLY_PARENT); | ||
PreBuildTrigger trigger = new PreBuildTrigger(); | ||
addEmailType( trigger ); | ||
publisher.getConfiguredTriggers().add( trigger ); | ||
MatrixBuild build = project.scheduleBuild2(0).get(); | ||
assertBuildStatusSuccess(build); | ||
|
||
|
||
assertThat( "Email should have been triggered, so we should see it in the logs.", build.getLog( 100 ), | ||
hasItems( "Email was triggered for: " + PreBuildTrigger.TRIGGER_NAME ) ); | ||
assertEquals( 1, Mailbox.get( "solganik@gmail.com" ).size() ); | ||
} | ||
|
||
public void testPreBuildMatrixBuildSendSlavesOnly() throws Exception{ | ||
addSlaveToProject(0,1,2); | ||
|
||
publisher.setMatrixTriggerMode(MatrixTriggerMode.ONLY_CONFIGURATIONS); | ||
PreBuildTrigger trigger = new PreBuildTrigger(); | ||
addEmailType( trigger ); | ||
publisher.getConfiguredTriggers().add( trigger ); | ||
|
||
|
||
MatrixBuild build = project.scheduleBuild2(0).get(); | ||
assertBuildStatusSuccess(build); | ||
assertEquals( 3, Mailbox.get( "solganik@gmail.com" ).size() ); | ||
} | ||
|
||
public void testPreBuildMatrixBuildSendSlavesAndParent() throws Exception{ | ||
addSlaveToProject(0,1); | ||
|
||
publisher.setMatrixTriggerMode(MatrixTriggerMode.BOTH); | ||
PreBuildTrigger trigger = new PreBuildTrigger(); | ||
addEmailType( trigger ); | ||
publisher.getConfiguredTriggers().add( trigger ); | ||
|
||
|
||
MatrixBuild build = project.scheduleBuild2(0).get(); | ||
assertBuildStatusSuccess(build); | ||
assertEquals( 3, Mailbox.get( "solganik@gmail.com" ).size() ); | ||
} | ||
|
||
|
||
private void addEmailType( EmailTrigger trigger ) | ||
{ | ||
trigger.setEmail( new EmailType() | ||
{{ | ||
setRecipientList( "solganik@gmail.com" ); | ||
setSubject( "Yet another Hudson email" ); | ||
setBody( "Boom goes the dynamite." ); | ||
}} ); | ||
} | ||
private void addSlaveToProject(int ... slaveInxes ) throws IOException{ | ||
AxisList list = new AxisList(); | ||
List<String> values = new LinkedList<String>(); | ||
for (int slaveInx : slaveInxes) { | ||
values.add(slaves.get(slaveInx).getLabelString()); | ||
} | ||
list.add(new Axis("label",values)); | ||
project.setAxes(list); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters