Line 18: |
|
return null;</pre> |
|
return null;</pre> |
|
|
|
|
- |
= Script to Set a Build Life Status if Any Tests Fail =
|
+ |
= Assign a Status Based on the Results of JUnit Tests =
|
|
|
|
|
|
Script Notes: |
|
Script Notes: |
|
* This script goes in an '''Assign Status''' step. |
|
* This script goes in an '''Assign Status''' step. |
|
|
|
|
- |
==== AHPSCRIPTS-37 ====
|
+ |
==== AHPSCRIPTS-36 ====
|
|
|
|
|
- |
<pre>import com.urbancode.anthill3.domain.test.*;
|
+ |
<pre>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.*;
|
|
|
|
|
- |
reports = TestReportFactory.getInstance().restoreAllForJobTrace(JobTraceLookup.getCurrent());
|
|
|
- |
for (int i=0; i<reports.length; i++) {
|
|
|
- |
if (reports[i].getNumberOfFailures() > 0) {
|
|
|
- |
return "Failed Tests";
|
|
|
- |
}
|
|
|
|
|
|
|
|
|
+ |
// 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;
|
|
} |
|
} |
- |
return null;</pre>
|
+ |
}
|
|
|
|
|
|
|
|
|
|
|
+ |
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</pre>
|