Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[FIXED JENKINS-8590] added option for controlling the firing for
MatrixProject.
- Loading branch information
Showing
with
262 additions
and 25 deletions.
- +58 −3 src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java
- +8 −1 src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java
- +27 −0 src/main/java/hudson/plugins/emailext/MatrixTriggerMode.java
- +3 −2 src/main/java/hudson/plugins/emailext/plugins/content/BuildStatusContent.java
- +11 −4 src/main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/config.jelly
- +12 −0 src/main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/help-matrixTriggerMode.html
- +5 −1 src/main/resources/hudson/plugins/emailext/Messages.properties
- +116 −0 src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherMatrixTest.java
- +22 −14 src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherTest.java
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
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
@@ -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
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
@@ -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> |
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
@@ -1,2 +1,6 @@ | ||
ExtendedEmailPublisherDescriptor.DisplayName=Editable Email Notification | ||
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 |
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
@@ -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