[ https://issues.jenkins-ci.org/browse/JENKINS-7859?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Slide-O-Mix reassigned JENKINS-7859: ------------------------------------ Assignee: branso Please clone the git repo, make the changes and issue a pull request. > Email-ext trigger for the transition from success to failure > ------------------------------------------------------------ > > Key: JENKINS-7859 > URL: https://issues.jenkins-ci.org/browse/JENKINS-7859 > Project: Jenkins > Issue Type: New Feature > Components: email-ext > Affects Versions: current > Reporter: branso > Assignee: branso > > Continuation from JENKINS-7858. Wasn't able to add a comment for some reason. > Email-ext currently does not have a trigger for when a build goes from > success to failure. The failure triggers on every failed build however the > patch the I'm suggesting will only trigger on the transition. > To add this feature change/add the following files > * hudson/plugins/emailext/EmailExtensionPlugin.java add the lines indicated > {code:java} > /* > * The MIT License > * > * Copyright (c) 2010, kyle.swee...@valtech.com, Stellar Science Ltd Co, K. > R. Walker > * > * Permission is hereby granted, free of charge, to any person obtaining a > copy > * of this software and associated documentation files (the "Software"), to > deal > * in the Software without restriction, including without limitation the > rights > * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell > * copies of the Software, and to permit persons to whom the Software is > * furnished to do so, subject to the following conditions: > * > * The above copyright notice and this permission notice shall be included in > * all copies or substantial portions of the Software. > * > * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE > * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > FROM, > * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN > * THE SOFTWARE. > */ > package hudson.plugins.emailext; > import hudson.Plugin; > import hudson.plugins.emailext.plugins.ContentBuilder; > import hudson.plugins.emailext.plugins.EmailContent; > import hudson.plugins.emailext.plugins.EmailTriggerDescriptor; > import hudson.plugins.emailext.plugins.content.*; > import hudson.plugins.emailext.plugins.trigger.*; > import hudson.plugins.emailext.plugins.trigger.FirstFailureTrigger; //add > line > /** > * Entry point of a plugin. > * > * <p> > * There must be one {@link Plugin} class in each plugin. > * See javadoc of {@link Plugin} for more about what can be done on this > class. > * > * @author kyle.swee...@valtech.com > */ > public class EmailExtensionPlugin extends Plugin { > @Override > public void start() throws Exception { > //We are adding different Content plugins to the list of > content types. > addEmailContentPlugin(new BuildLogContent()); > addEmailContentPlugin(new BuildLogRegexContent()); > addEmailContentPlugin(new BuildNumberContent()); > addEmailContentPlugin(new BuildStatusContent()); > addEmailContentPlugin(new BuildURLContent()); > addEmailContentPlugin(new ChangesSinceLastBuildContent()); > addEmailContentPlugin(new > ChangesSinceLastSuccessfulBuildContent()); > addEmailContentPlugin(new > ChangesSinceLastUnstableBuildContent()); > addEmailContentPlugin(new EnvContent()); > addEmailContentPlugin(new FailedTestsContent()); > addEmailContentPlugin(new HudsonURLContent()); > addEmailContentPlugin(new ProjectNameContent()); > addEmailContentPlugin(new ProjectURLContent()); > addEmailContentPlugin(new SVNRevisionContent()); > addEmailContentPlugin(new CauseContent()); > addEmailContentPlugin(new JellyScriptContent()); > addEmailTriggerPlugin(PreBuildTrigger.DESCRIPTOR); > addEmailTriggerPlugin(FailureTrigger.DESCRIPTOR); > addEmailTriggerPlugin(StillFailingTrigger.DESCRIPTOR); > addEmailTriggerPlugin(UnstableTrigger.DESCRIPTOR); > addEmailTriggerPlugin(StillUnstableTrigger.DESCRIPTOR); > addEmailTriggerPlugin(SuccessTrigger.DESCRIPTOR); > addEmailTriggerPlugin(FixedTrigger.DESCRIPTOR); > addEmailTriggerPlugin(FirstFailureTrigger.DESCRIPTOR); //add > line > } > private void addEmailContentPlugin(EmailContent content) { > try { > ContentBuilder.addEmailContentType(content); > } catch (EmailExtException e) { > System.err.println(e.getMessage()); > } > } > private void addEmailTriggerPlugin(EmailTriggerDescriptor trigger) { > try { > ExtendedEmailPublisher.addEmailTriggerType(trigger); > } catch (EmailExtException e) { > System.err.println(e.getMessage()); > } > } > } > {code} > * Create the file > hudson/plugins/emailext/plugins/trigger/FirstFailureTrigger.java with the > following code: > {code:java} > package hudson.plugins.emailext.plugins.trigger; > import hudson.model.AbstractBuild; > import hudson.model.Result; > import hudson.plugins.emailext.plugins.EmailTrigger; > import hudson.plugins.emailext.plugins.EmailTriggerDescriptor; > public class FirstFailureTrigger extends EmailTrigger { > public static final String TRIGGER_NAME = "First Failure"; > > @Override > public boolean trigger(AbstractBuild<?,?> build) { > > Result buildResult = build.getResult(); > > if (buildResult == Result.FAILURE) { > AbstractBuild<?,?> prevBuild = build.getPreviousBuild(); > if (prevBuild != null && (prevBuild.getResult() == > Result.SUCCESS)) { > return true; > } > } > return false; > } > > @Override > public EmailTriggerDescriptor getDescriptor() { > return DESCRIPTOR; > } > > public static DescriptorImpl DESCRIPTOR = new DescriptorImpl(); > > public static final class DescriptorImpl extends EmailTriggerDescriptor > { > > public DescriptorImpl() { > addTriggerNameToReplace(SuccessTrigger.TRIGGER_NAME); > } > > @Override > public String getTriggerName() { > return TRIGGER_NAME; > } > @Override > public EmailTrigger newInstance() { > return new FirstFailureTrigger(); > } > @Override > public String getHelpText() { > return "An email will be sent when the build status > changes from \"Successful\" " + > "to \"Failure\""; > } > > } > > @Override > public boolean getDefaultSendToDevs() { > return true; > } > @Override > public boolean getDefaultSendToList() { > return true; > } > } > {code} > Rebuild the source and load into Hudson. You will now have a new option to > select first failure trigger. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jenkins-ci.org/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira