Versions Compared

Key

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

...

End Release After Snapshot Deploys to Production

Info

Note that this function may no longer needed as Release Settings incorporate this functionality.

To take advantage of ending a release after a pipeline execution completes you can create a new listener and select the Pipeline Stage Completed. You will then need to check whether the completed stage is the final stage in the pipeline. You can do this in a number of ways. One way is shown below by checking the environment code and comparing it to our final PROD stage.

...

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 = "endReleaseListener";
LOG.info("Running listener: ${listenerName}");
         
if(EVENT.payload.environment.environmentCode.equals("PROD")){
     LOG.setMessage("Release ${EVENT.payload.release.releaseName} has completed moving through the pipeline. Ending release.");
     FLEXDEPLOY.endReleaseforceEndRelease(EVENT.payload.release.releaseId);
}

...

Code Block
languagegroovy
//Carry out any custom action you wish for this event. Check out the snippets for reference or ideas.
def listenerName = "TaskCreated";
LOG.info("Running listener: ${listenerName}");

def channel = 'testing';

//Slack account code defined in TopologyConfiguration->Integration->Messaging
def account = 'SLACK';

//Create and post a FlexDeploy Slack Message object with interactive buttons to approve/reject
def message = SLACK.makeTaskCreatedMessage(EVENT.payload,true);
def tsId = SLACK.postMessage(account,channel,message);

LOG.setMessage("Posted task ${EVENT.payload.taskId} to Slack");

...

In the below example we make use of the ChangeManagementSystemService to allow us to create an incident through FlexDeploy’s internal ServiceNow integration. The only thing that needs to be configured ahead of time is your ServiceNow instance in TopologyConfiguration->Integrations->ChangeManagement>Change Management

...

Create Incident Script

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 = "Create Incident";
LOG.info("Running listener: ${listenerName}");

def cmsFields = [:];
cmsFields.short_description = "Deployment failed for ${EVENT.payload.project.projectName}";
cmsFields.description = "Deployment failed for ${EVENT.payload.project.projectName}. Environment ${EVENT.payload.environment.environmentName} executionid ${EVENT.payload.workflowExecutionId} requestor ${EVENT.payload.updatedBy}";
 
LOG.fine("Creating Service Now Incident ${cmsFields}");

def cmsObject = FLEXDEPLOY.createIncidentForWorklowRequest(EVENT.payload.workflowRequest.workflowRequestId, cmsFields, "SERVICENOW",null);
LOG.setMessage("Successfully created Service Now Incident ${cmsObject.getNumber()}");

...

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.testRun.testSetstestSuiteExec.each{ testSettestSuite ->
  LOG.fine("Processing test setsuite execution ${testSettestSuite.nametestSuiteExecutionId}");
  
  testSettestSuite.testDefinitionstestExecutions.each{ testDeftestExec ->
    LOG.fine("Processing test defexecution ${testDeftestExec.name}");
    
    def testDefNametestingTool = testDeftestExec.nametoolName;
    def
testingTool = testDef.testingTool;     
    testDef.resultstestExec.testResults.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);
}

...

Update Package to Completed After Production Deployment

Info

Note that this function may no longer needed as Release Settings incorporate this functionality.

You may want to change a package’s status to completed to indicate it successfully deployed to its final environment. This webhook handles changing the status for you using the Workflow Completed Event. You could update the filter to only update the status for certain projects, releases, instances, etc. The listener also handles removing the package from its release first, as a package cannot be marked completed if it’s in an active release.

Webhook Listener

Code Block
languagegroovy
​def releaseName = EVENT.payload.release.releaseName
def projectId = EVENT.payload.project.projectId
def packageName = EVENT.payload.packageName

if (releaseName != null)
{
  FLEXDEPLOY.removeProjectsFromRelease(releaseName, [new flexagon.fd.model.pojos.rest.release.ReleaseProjectsPojo(projectId, packageName, false)])
}

FLEXDEPLOY.updatePackageStatus(projectId, packageName, "COMPLETED")

...