Versions Compared

Key

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

...

Code Block
languagegroovy
import flexagon.ff.common.core.exceptions.FlexCheckedException;

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

//Prior to 5.4.0.1 this function only returned a list of input streams. Update accordingly
//The second argument specifies we only want the error streams returned.
def streams = FLEXDEPLOY.getPluginLogInputStreams(EVENT.payload.workflowExecutionId, true);

//upfront validation on streams
if(!streams || streams.size() == 0) {
  LOG.setMessage("Received failure event but couldn't find any plugin log streams");
  return;
}

//We should only ever have one errored plugin execution, so grab first entry.
def failedPlugin = streams.entrySet().iterator().next();

//create our form data body
def propertiesbody = getJiraProperties('JIRA');

LOG.info("${EVENT.payload.issueNumbers}REST.getClient().createFormDataWithInputStream(['file': failedPlugin.getValue()], "${failedPlugin.getKey()}.txt");

for(def issue: EVENT.payload.issueNumbers) {
properties = getJiraProperties('JIRA');

LOG.info("Upload logs to issue: ${issue}");
  
  //create our form data body
  failedPlugin.getValue().reset();
  def body = REST.getClient().createFormDataWithInputStream(['file': failedPlugin.getValue()], "${failedPlugin.getKey()}.txtEVENT.payload.issueNumbers}");

for(def issue: EVENT.payload.issueNumbers) {
  LOG.info("Upload logs to issue: ${issue}");
  
  //send request
  def client = REST.getClient().url(properties.url).addHeader('X-Atlassian-Token', 'no-check').basicauth(properties.user,properties.password);
  def response = client.path("/rest/api/2/issue/${issue}/attachments").post(body);
  LOG.setMessage("Uploaded logs to ${issue}. Response: ${response.getResponseCode()}");
}

//helper function to get jira properties from integration instance
def getJiraProperties(String code) {
  def instance = FLEXDEPLOY.findIntegrationInstance(code,'ITS');
  def properties = instance.getProperties();
  def url = properties.find { it.getPropertyName() == 'JIRA_URL' }.getPropertyValue();
  def user = properties.find { it.getPropertyName() == 'JIRA_USER_NAME' }.getPropertyValue();
  def password = properties.find { it.getPropertyName() == 'JIRA_PASSWORD' }.getPropertyValue();
  return ['url':url, 'user': user, 'password': password];
}

...

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.

...