Versions Compared

Key

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

...

This sample sends an interactive message to a Microsoft Teams channel that allows members of the channel to approve or reject an associated FlexDeploy task. As shown in this script, you can add conditions to handle sending to multiple different channels in one listener depending on some condition. (e.g. environment, pipeline, release, etc.) You could also apply similar logic to the webhook listener filter to customize when and where the Teams message should be sent.

See the incoming samples also. An incoming webhook is needed to capture the button clicks that users perform on the Teams messages and ultimately approve/reject the task in FlexDeploy.

...

To prevent user error when creating a work item, you set the default Assignee for the Work Item to the user who created the work item if it was not set. This webhook will only set the assignee at creation time using the Work Item Created Event.

Webhook Listener

Code Block
languagegroovy
FlxWorkItemDataObject workItem = FLEXDEPLOY.findWorkItemByNumber(EVENT.payload.workItemNumber)

// check if the assignee is not already set
if (!workItem.getAssignee()?.trim())
{
  FLEXDEPLOY.updateWorkItemAssignee(EVENT.payload.workItemNumber, EVENT.payload.createdBy)
}

...

Select the Event Types as Project Created from the drop-down

...

Code Block
languagegroovy
import flexagon.fd.model.pojos.rest.project.*;
import flexagon.fd.model2.pojo.ProjectDataObject;

LOG.info("Running listener: ${FUNCTION_NAME}");
LOG.info(EVENT.payload.projectName);

def projectDataObject = new ProjectDataObject();
projectDataObject.setProjectId(EVENT.payload.projectId);

def resProjects = FLEXDEPLOY.searchProjects(projectDataObject,10,0).getItems();

def proj = new ProjectPojo();
proj.setWebhooksEnabled(true);

for (def project:resProjects)
{
  def projectId = project.getProjectId();
  FLEXDEPLOY.patchProject(projectId, proj);
}
LOG.setMessage("Webhook is now enabled for Project " + EVENT.payload.projectName);

...