This page lists notification template scripts to be used in conjunction with notification schemes. 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.
Script notes:
import com.urbancode.anthill3.domain.jobtrace.*; import com.urbancode.anthill3.domain.workflow.*; import com.urbancode.anthill3.runtime.paths.*; import com.urbancode.devilfish.services.var.VarService; import java.io.*; private String getFileAsString(File file) throws IOException { StringBuffer result = new StringBuffer(); if (file.exists() && file.isFile()) { InputStream inStream = new FileInputStream(file); try { byte[] buffer = new byte[4096]; int length = 0; while ((length = inStream.read(buffer)) > 0) { result.append(new String(buffer, 0, length)); } } finally { try { inStream.close(); } catch (Exception e) {} } } return result.toString(); } String REPORT_NAME = "Fitnesse Reports"; // change to the name of your reports WorkflowCase workflow = (WorkflowCase) context.get("workflow"); JobTrace[] jobTraceArray = workflow.getJobTraceArray(); // find the job trace you want in some meaningful way JobTrace jobTrace = jobTraceArray[0]; VarService vs = VarService.getInstance(); String reportsPath = PublishPathHelper.getInstance().getPublishPath(jobTrace,REPORT_NAME); File reportDir = new File(vs.resolve(reportsPath)); if (reportDir.exists() && reportDir.isDirectory()) { File[] reportFiles = reportDir.listFiles(); String[] reports = new String[reportFiles.length]; for (int f=0; f<reportFiles.length; f++) { reports[f] = getFileAsString(reportFiles[f]); } context.put("reports", reports); }
import com.urbancode.anthill3.domain.jobtrace.*; import com.urbancode.anthill3.domain.workflow.*; import com.urbancode.anthill3.runtime.paths.*; import com.urbancode.anthill3.services.file.*; import com.urbancode.devilfish.services.file.FileInfo; import com.urbancode.devilfish.services.var.VarService; import com.urbancode.anthill3.domain.workflow.WorkflowCase; import java.io.*; private String getStreamAsString(InputStream inStream) throws IOException { StringBuffer result = new StringBuffer(); try { byte[] buffer = new byte[4096]; int length = 0; while ((length = inStream.read(buffer)) > 0) { result.append(new String(buffer, 0, length)); } } finally { try { inStream.close(); } catch (Exception e) {} } return result.toString(); } WorkflowCase workflow = (WorkflowCase)context.get("workflow"); String STEP_NAME = "echoer"; // change to the name of the step jobTraces = workflow.getJobTraceArray(); for (int j=0; j<jobTraces.length; j++){ StepTrace[] stepTraces = jobTraces[j].getStepTraceArray(); for (int s=0; s<stepTraces.length; s++) { if (STEP_NAME.equals(stepTraces[s].getName())) { // found the step CommandTrace cmdTrace = stepTraces[s].getCommandTraceArray()[0]; FileInfo outputFile = LogPathHelper.getInstance().getLogFileInfoArray(cmdTrace)[0]; InputStream inStream = FileInfoService.getInstance().getFileInfoAsStream(outputFile); String output = getStreamAsString(inStream); context.put("output", output); break; } } }
Context
import com.urbancode.anthill3.runtime.scripting.helpers.*; workflow = context.get("workflow"); WorkflowErrorSummary wes = ErrorHelper.getWorkflowErrorSummary(workflow); int arrayLength = wes.getJobTraceErrorSummaryArray().length; context.put("workflowErrorSummary", wes); context.put("jtesal", arrayLength);
Template
## BEGIN SECTION Subject Unit Testing ## END SECTION Subject ## BEGIN SECTION Body ## PROPERTY Content-Type: text/html ## PROPERTY X-Priority: 3 #if ($workflowErrorSummary.logErrors || $jtesal > 0) <h2> Workflow Error Log </h2> #if ($jtesal == 0) <ppre>$workflowErrorSummary.logErrors</ppre> #end #foreach($errorTrace in $workflowErrorSummary.jobTraceErrorSummaryArray) <h3>$errorTrace.jobName</h3> <ppre>$errorTrace.logErrors</ppre> <ul> #foreach($step in $errorTrace.stepTraceErrorSummaryArray) <li> <b>$step.stepName</b><br> #foreach($commandError in $step.commandTraceErrorSummaryArray) #if ($commandError.outputErrors) <ppre>$commandError.outputErrors</ppre> #else <ppre>$commandError.logError</ppre> #end <br><br> #end </li> #end </ul> #end #end ## END SECTION Body
CONTEXT SCRIPT:
import com.urbancode.anthill3.domain.workflow.*; WorkflowCase workflow = (WorkflowCase) context.get("workflow"); context.put("testValue", workflow.getBuildRequest().getProperty("test.property"));
TEMPLATE TEXT:
$testValue
CONTEXT
buildLife = workflow.getBuildLife(); issues = IssueHelper.getIssueArray(buildLife); issues = issues.length > 0 ? issues : null; System.out.println("issues: " + issues); context.put("issues", issues);
TEMPLATE
#if ($issues) <h2>Issues</h2> <table> <tr> <th>Issue ID</th> <th>Name</th> <th>Description</th> </tr> #foreach($issue in $issues) <tr> <td><a href="$issue.issueUrl">$issue.issueId</a></td> <td>$issue.name</td> <td>$issue.description</td> </tr> #end </table> #end
#set($buildLife = $workflow.BuildLife) Dependencies: #foreach($dep in $buildLife.dependencyBuildLifeArray) $dep.codestationProject.name ($dep.latestStampValue) #end