Pre-Condition: Step

This page lists step-precondition scripts that are 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.

Step Pre-Condition That Works Based on a Workflow Name

AHPSCRIPTS-114

// This script will run a step if the name of the workflow is "Workflow Name"
import com.urbancode.anthill3.domain.workflow.*;
import com.urbancode.anthill3.runtime.scripting.helpers.*;

Workflow workflow = WorkflowLookup.getCurrent();

boolean isTrue = false;
String name = "";

return new Criteria() {
    public boolean matches(Object obj) {
        name = workflow.getName();
        if("Workflow Name".equals(name)){
         isTrue = true;
        }else{
            isTrue = false;
          }
      
       return isTrue;
    }
}

Property-Based

  • The example checks to make sure that all previous steps in the job have completed successfully (or with a warning) and that the property named "buildType" resolves to "official". It's a simple example of only doing a particular step based on a property.

AHPSCRIPTS-65

// All previous steps are successful and the build type is official 
 Logic.and( 
   StepStatus.allPriorIn(new JobStatusEnum[] { JobStatusEnum.SUCCESS, JobStatusEnum.SUCCESS_WARN }), 
   Property.is("buildType", "official") 
 );

Run if Triggered by Particular Schedule

  • This script will allow a step to run if it was triggered by a specific schedule Change the name of "Nightly 1am (expression)" to be your schedule name.

AHPSCRIPTS-94

import com.urbancode.anthill3.domain.buildrequest.BuildRequest; 
 import com.urbancode.anthill3.domain.buildrequest.*; 
 BuildRequest request = BuildRequestLookup.getCurrent(); 
 String scheduleName = null; 
 return new Criteria() { 
     public boolean matches(Object obj) { 
      if (RequestSourceEnum.SCHEDULED.equals(request.getRequestSource())) { 
          scheduleName = request.getRequester().getSchedule().getName(); 
       } 
      return "Nightly 1am (expression)".equals(scheduleName); 
     } 
 }