This page lists event-selector (used for event triggers) scripts listed in the scripting site. These scripts were taken straight from the public JIRA site. Please note that some scripts may be snippets and probably WILL need modification to work properly for your situation. Treat these as templates that you can modify from.
Script Notes:
import com.urbancode.anthill3.domain.workflow.*; import com.urbancode.anthill3.domain.buildlife.*; result = false; if (event instanceof WorkflowEvent && event.getCase().isComplete() && event.getCase().getStatus().isSuccess()) { currentSuccess = event.getCase().getBuildLife(); lastFailure = BuildLifeFactory.getInstance().restorePriorMostRecentFailureForProfile(currentSuccess, currentSuccess.getProfile()); lastSuccess = BuildLifeFactory.getInstance().restorePriorMostRecentSuccessForProfile(currentSuccess, currentSuccess.getProfile()); if (lastFailure != null) { if (lastSuccess == null || lastFailure.getStartDate().after(lastSuccess.getStartDate())) { // This is a build fix result = true; } } } return result;
This script checks the status of the previous build. If the previous status is the same as the current status, it will not notify. If the status has changed (i.e. from Success to Failure or viceversa) then it will notify.
/****** * @auther: Steve Boone */ import com.urbancode.anthill3.domain.workflow.*; import com.urbancode.anthill3.dashboard.*; boolean result = false; if (event instanceof WorkflowEvent && event.getCase().isComplete()) { Long wid = event.getCase().getWorkflow().getId(); BuildLifeWorkflowCaseSummary[] blwcs=DashboardFactory.getInstance().getBuildLifeWorkflowSummariesByWorkflow(wid, null, new Integer(2)); if(blwcs.length == 2){ if(!blwcs[0].getStatus().equals(blwcs[1].getStatus())){ result=true; } } } return result;
Another alternative method that is more accurate:
import com.urbancode.anthill3.domain.buildlife.*; import com.urbancode.anthill3.domain.workflow.*; import com.urbancode.anthill3.dashboard.*; boolean result = false; if (event instanceof WorkflowEvent && event.getCase().isComplete()) { buildLifeFact = BuildLifeFactory.getInstance(); buildLife = event.getCase().getBuildLife(); buildStatus = event.getCase().getStatus(); priorSuccess = buildLifeFact.restorePriorMostRecentSuccessForProfile(buildLife, buildLife.getProfile()); priorFailure = buildLifeFact.restorePriorMostRecentFailureForProfile(buildLife, buildLife.getProfile()); if (priorSuccess != null && priorFailure != null) { boolean previousWasSuccess = priorSuccess.getActualWorkspaceDate().after(priorFailure.getActualWorkspaceDate()); if (previousWasSuccess != buildStatus.isSuccess()) { result = true; } } else if (buildStatus.isSuccess() && priorFailure != null) { result = true; } else if (!buildStatus.isSuccess() && priorSuccess != null) { result = true; } else { result = false; } } return result;
import com.urbancode.anthill3.domain.workflow.*; import com.urbancode.anthill3.domain.buildlife.*; import com.urbancode.anthill3.domain.servergroup.*; result = false; if(event instanceof WorkflowEvent){ if(event.getCase().isComplete()) { ServerGroup sg = event.getCase().getServerGroup(); if("QA".equals(sg.getName())){ result = true; }//end if }//end if }//end if return result;