JIRA - The Dreaded Attachment ID Mystery...
One of the most annoying problems to solve (for me) has been creating a Custom JIRA email notification and Embedding an attachment or displaying a URL to the attachment image.
Like Pushing an elephant up the stairs... |
I should also mention that I want to avoid buying some expensive plugin to do this... So, that being said,,,, I was able to build a relatively simple solution with the JJupin (SIL scripting) plugin.
So, the first problem you will encounter when trying to do anything with a JIRA attachment is getting the JIRA attachment's ID.
To do so, I had to do a few things.
- Get the File Path to the attachment by doing the following:
In the workflow Post-function where the user adds the attachment I adding the following SIL Script:
string [] filePaths = getAttachmentPath(key, "*.png");
Associates the File Path of the attachment to the JIRA key (making this solution dynamic)
This will capture a link that looks like the following:
/export/disk01/data/jira/home_standalone/attachments/TEST/TEST-163/92584
- You will use a Calculated Text Field
Using a Calculated Text Field which is part of the JIRA Misc Custom Fileds Plugin (Free!) you can add the following simple Java line to parse the Attachment ID (by it's placement in the link above [67] represent the placement of the Attachment ID):
<!-- @@Formula: issue.get("customfield_13506")==null ? null : issue.get("customfield_13506").substring(67) -->
This gives us the the Attachent ID: 92584 for the associated JIRA issues.
I am now able to add a dynamic link to the attachment to an email notification with the following SIL scrip:
string Attachment_URL = "https://Your.JIRA.Instance/secure/attachment/" + #{AttachID} + "/" + attachments;
Note: #{AttachID} is the name of my Calculated Text Field
Comments
Post a Comment