Event Selector

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.

Trigger on First Success After Failed Workflow

Script Notes:

  • This script goes in System --> Event Selector

AHPSCRIPTS-11

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;

Notify Only When Status of Workflow Changed

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.

AHPSCRIPTS-19

/******
 * @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;

Notify Based on Environment in Which a Workflow Ran

  • This script is intended to be an Event Selector script and should be used as part of a Notification Scheme. It determines when people should be notified. If the a workflow runs in a specific environment (the script as posted, checks for "QA") then it will return true. Using this script, you can choose to notify a group of users when deployments happen to specific environments.

AHPSCRIPTS-115

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;