Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
//Carry out any custom action you wish for this event. Check out the documentation for reference or ideas.
//Optionally filter out events you dont want to execute by returning false on the filter script tab.
def listenerName = "Tests Completed";
LOG.info("Running listener: ${listenerName}");

def builder = new StringBuilder();
builder.append("<h1 style=\"padding: 10px 0\">Tests ${EVENT.payload.testRun.runStatus} for ${getProjectLink(EVENT.payload.project.projectName, EVENT.payload.project.projectId)} in ${EVENT.payload.environment.environmentName}</h1>");

builder.append("<table><tr><th style=\"padding: 0 10px 5px 0\">Test Def Name</th><th style=\"padding: 0 10px 5px 0\">Testing Tool</th><th style=\"padding: 0 10px 5px 0\">Test Case Name</th><th style=\"padding: 0 10px 5px 0\">Status</th></tr>");

EVENT.payload.testRuntestSuiteExec.testSets.each{ testSettestSuite ->
  LOG.fine("Processing test suite setexecution ${testSettestSuite.nametestSuiteExecutionId}");
  
  testSettestSuite.testDefinitionstestExecutions.each{ testDeftestExec ->
    LOG.fine("Processing test defexecution ${testDeftestExec.name}");
    
    def testDefName = testDef.name;
    def testingTool = testDeftestExec.testingTooltoolName;
    
    testDeftestExec.resultstestResults.each{ testResult -> 
      def testCaseName = testResult.testCaseName;
      def status = testResult.status;
      
      builder.append("<tr><td style=\"padding-right: 10px\">${testDefName}</td><td style=\"padding-right: 10px\">${testingTool}</td><td style=\"padding-right: 10px\">${testCaseName}</td><td style=\"padding-right: 10px\">${status}</td></tr>");
    }
  }
}

builder.append("</table>");

def htmlMessage = builder.toString();

LOG.fine("Sending test results table to Teams: ${htmlMessage}");
MICROSOFTTEAMS.sendTeamsMessage("TEAMS","FD Developers","Testing",htmlMessage,null);

LOG.setMessage("Successfully sent test results message to teams for ${EVENT.payload.project.projectName}");

def getProjectLink(String pProjectName, Long pProjectId)
{
  String link = String.format("%s/flexdeploy/faces/projects?objecttype=Project&projectid=%s&projectname=%s", FLEXDEPLOY.getFlexDeployBaseUrl(), pProjectId, pProjectName);
  return String.format("<a href=%s>%s</a>", link, pProjectName);
}

...