(→Script to Set a Build Life Status if Any Tests Fail - - Initial)
|
(Fixed formatting)
|
Line 26: | |||
<pre>import com.urbancode.anthill3.domain.singleton.serversettings.*; | <pre>import com.urbancode.anthill3.domain.singleton.serversettings.*; | ||
- | import com.urbancode.anthill3.domain.buildlife.*; | + | import com.urbancode.anthill3.domain.buildlife.*; |
- | import com.urbancode.anthill3.domain.jobtrace.*; | + | import com.urbancode.anthill3.domain.jobtrace.*; |
- | import com.urbancode.anthill3.domain.jobtrace.buildlife.*; | + | import com.urbancode.anthill3.domain.jobtrace.buildlife.*; |
- | import com.urbancode.anthill3.runtime.scripting.helpers.*; | + | 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(); | ||
- | // BUILD_STEP_NAME: Name of the step within the job that should be inspected | + | if(token.equals(failures)){ |
- | String BUILD_STEP_NAME = "build"; | + | String temp = st.nextToken(); |
+ | if(temp != null){ | ||
- | BuildLifeJobTrace jobTrace = JobTraceLookup.getCurrent(); | + | char a = temp.charAt(0); |
- | StepTrace[] stepTraceArray = jobTrace.getStepTraceArray(); | + | String s = a.toString(); |
- | StepTrace stepTrace = null; | + | int i = Integer.parseInt(s); |
- | for (int j = 0; j < stepTraceArray.length && stepTrace == null; j++) { | + | if(i > 0){ |
- | if (stepTraceArray[j].getName().equalsIgnoreCase(BUILD_STEP_NAME)) { | + | hasFailures = true; |
- | stepTrace = stepTraceArray[j]; | + | }//end if |
- | break; | + | }//end if |
- | } | + | }//end if |
- | } | + | else{ |
+ | if(token.equals(errors)){ | ||
+ | String temp = st.nextToken(); | ||
- | String outputLog = LogHelper.getOutput(stepTrace.getCommandTraceArray()[0]); | + | if(temp != null){ |
- | String failures = "Failures:"; | + | char a = temp.charAt(0); |
- | String errors = "Errors:"; | + | String s = a.toString(); |
- | boolean hasFailures = false; | + | int i = Integer.parseInt(s); |
- | StringTokenizer st = new StringTokenizer(outputLog); | + | if(i > 0){ |
- | String token = null; | + | return StatusLookup.getStatusByName("ORANGE"); |
- | BuildLife bl = BuildLifeLookup.getCurrent(); | + | }else{ |
+ | if(hasFailures){ | ||
- | while(st.hasMoreTokens()){ | + | return StatusLookup.getStatusByName("YELLOW"); |
- | token = st.nextToken(); | + | }else{ |
- | if(token.equals(failures)){ | + | return StatusLookup.getStatusByName("Success"); |
- | String temp = st.nextToken(); | + | }//end else |
- | if(temp != null){ | + | }//end else |
- | char a = temp.charAt(0); | + | }//end if |
- | String s = a.toString(); | + | }//end if |
- | int i = Integer.parseInt(s); | + | }//end else |
- | if(i > 0){ | + | }//end while</pre> |
- | 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> |