This page lists assign status scripts (used for status selectors) 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.
import com.urbancode.anthill3.services.jobs.JobStatusEnum; project = ProjectLookup.getCurrent(); success = project.getStatusGroup().SUCCESS(); failure = project.getStatusGroup().FAILURE(); result = success; workflow = WorkflowLookup.getCurrentCase(); jobArray = workflow.getJobTraceArray(); for (int j=0; j<jobArray.length; j++) { stepArray = jobArray[j].getStepTraceArray(); for (int s = 0; s < stepArray.length; s++) { if (!stepArray[s].isIgnoreMyFailures() && JobStatusEnum.FAILED.equals(stepArray[s].getStatus())) { result = failure; break; } } if (failure.equals(result)) { break; } } return result;
Script Notes:
import com.urbancode.anthill3.domain.test.*; reports = TestReportFactory.getInstance().restoreAllForJobTrace(JobTraceLookup.getCurrent()); for (int i=0; i<reports.length; i++) { if (reports[i].getNumberOfFailures() > 0) { return "Failed Tests"; } } return null;
Script Notes:
import com.urbancode.anthill3.domain.singleton.serversettings.*; import com.urbancode.anthill3.domain.buildlife.*; import com.urbancode.anthill3.domain.jobtrace.*; import com.urbancode.anthill3.domain.jobtrace.buildlife.*; import com.urbancode.anthill3.runtime.scripting.helpers.*; // BUILD_STEP_NAME: Name of the step within the job that should be inspected String BUILD_STEP_NAME = "build"; BuildLifeJobTrace jobTrace = JobTraceLookup.getCurrent(); StepTrace[] stepTraceArray = jobTrace.getStepTraceArray(); StepTrace stepTrace = null; for (int j = 0; j < stepTraceArray.length && stepTrace == null; j++) { if (stepTraceArray[j].getName().equalsIgnoreCase(BUILD_STEP_NAME)) { stepTrace = stepTraceArray[j]; break; } } String outputLog = LogHelper.getOutput(stepTrace.getCommandTraceArray()[0]); String failures = "Failures:"; String errors = "Errors:"; boolean hasFailures = false; StringTokenizer st = new StringTokenizer(outputLog); String token = null; BuildLife bl = BuildLifeLookup.getCurrent(); while(st.hasMoreTokens()){ token = st.nextToken(); if(token.equals(failures)){ String temp = st.nextToken(); if(temp != null){ char a = temp.charAt(0); String s = a.toString(); int i = Integer.parseInt(s); if(i > 0){ hasFailures = true; }//end if }//end if }//end if else{ if(token.equals(errors)){ String temp = st.nextToken(); if(temp != null){ char a = temp.charAt(0); String s = a.toString(); int i = Integer.parseInt(s); if(i > 0){ return StatusLookup.getStatusByName("ORANGE"); }else{ if(hasFailures){ return StatusLookup.getStatusByName("YELLOW"); }else{ return StatusLookup.getStatusByName("Success"); }//end else }//end else }//end if }//end if }//end else }//end while
Script Notes:
import com.urbancode.anthill3.runtime.scripting.helpers.*; import com.urbancode.anthill3.domain.status.*; import com.urbancode.anthill3.domain.buildlife.*; Status fail = StatusLookup.getStatusByName("Failed Tests"); BuildLife current = BuildLifeLookup.getCurrent(); if(current.hasStatus(fail)){ commandOutput.println("Failed Status detected!!!"); throw new Exception(); } else return null;
import com.urbancode.anthill3.domain.buildlife.BuildLife; import com.urbancode.anthill3.domain.jobtrace.JobTrace; import com.urbancode.anthill3.domain.test.TestReport; import com.urbancode.anthill3.domain.test.TestReportFactory; BuildLife currentBuildLife = BuildLifeLookup.getCurrent(); TestReport[] reports = TestReportFactory.getInstance().restoreAllForBuildLife(currentBuildLife); for (int i=0; i<reports.length; i++) { //System.out.println("reports.length: " + reports.length); //System.out.println("numFailures: " + reports[i].getNumberOfFailures()); if (reports[i].getNumberOfFailures() > 0) { return StatusLookup.getStatusByName("failure"); } } return StatusLookup.getStatusByName("success");
SCREENSHOT