JIRA Automation with SIL Scripts



I have been developing JIRA workflows for a couple of years now and thought I might be able to help others by posting some reusable scripts.  I have created these simple scripts using the JJupin plugin for JIRA.
If you are currently not using the JJupin plugin for JIRA it is worth a look:
http://www.kepler-rominfo.com/pages/solutions/jira-plugins





Control Assignee based on Custom field Selection

The following script will allow you to set the issue assignee based on the value chosen from a select field (custom field name = #{Project Type }) - I have used this to automate a very complex workflow and its corresponding subtasks.  If the #{User*} customfields are 'User Picker' field types this will allow for a very robust solution requiring little to no maintenance.

if (#{Project Type } == "option1")
    {
assignee = #{User1};
    }
else {
    if (#{Project Type } == "option2")
    assignee = #{User2};

else {
    if (#{Project Type } == "option3")
    assignee = #{User3};
    }
}

// The users are custom user select fields



Automatically Set Issue Due Date

Applying an issue due date is handy for dashboarding (traffic Lights) or email escalations (I will show you these soon!).  If your business need dictates that a process SLA is to have an issue resolved in 4 weeks, the following simple script will work for you:

dueDate = currentDate() + (interval)"4w";




Issue Age since last info received

Another simple script to display the time since an issue was last worked on.  This was used with a SIL custom field (JIRA - Kepler Custom fields plugin *Free)   I have used this to drive company statistics and trigger dashboard traffic lights.




if (isNotNull(day(#{Last Date Info Received})))
{
interval age = currentDate() - #{Last Date Info Received};
return age;
}
else
{
return "Due Date Needed";
}


Populate a Parent task customfield with value from a Subtask customfield

Now this is truly amazing!!!  With just this simple line of code in a SIL postfunction I am able to take a value from a subtask customfield (QC Analyst) and populate the parent issue custom field (QA Analyst) :

parent.#{QC Analyst} = #{QC Analyst};

Once the parent task has received this value I am able to assign a QC Analyst to additional subtasks or other stages in the parent task taking process automation to the next level!!!



Send HTML email with SIL Postfunction

In my opinion that is one of the most impressive things you can do using JJupin (SIL) scripting in JIRA.  You can create a Custom HTML email pulling custom field data in a nicely formatted package with out having to reboot!!!   

Call a SIL script in you post function similar to this:
**this is an example of how to create the variables that you will pull into the HTML**

string htmlTemplate = "my_html_template.tpl";
string template = "my_html_template.tpl";
string cmt = lastCommentDetails["text"];
string issuetype = issueType;
string desc = description;
string host = Hosts;
string reason = customfield_12093;
string requested = userFullName(customfield_10885);
string scadaapp = userFullName(customfield_10982);
string ccoapp = userFullName(customfield_13393);
print(attachments);
string [] filePaths = getAttachmentPath(key, "test1.png");
string subt = subtasks(key);

sendHtmlEmail(from, to, cc, subject, htmlTemplate, language, attachments);

place you template in the  jira.home.dir/kepler/emails directory and call as displayed at the top of the script.

Here in a example HTML Template that should be a good starting point for you (copy to Notepad ++ and formatting should look somewhat human readable!!!):

<html>
<head>
<style>
table {font-family: Arial,FreeSans,Helvetica,sans-serif; font-size:12px}
table{border-collapse:collapse;}
strong {color: #505050; font-weight:normal}
</style>
</head>
<body>
<table>
    <tr>
                <td valign=top style='background:#326ca6;'>
                              <img id="_x0000_i1025" src="https://My_JIRA_Instance.com/s/en_CA-s0p7la/6340/4/_/images/jira111x30.png">
                        </td>
      </tr>
    <tr>
                  <td style='border:none; padding:0 10pt 10pt 0'>
                              <br/>
                              <br/>
                              $recipient$,<br/>
                              <br/>
                              <a href=>$summary$</a> has been approved and is now complete.  
                    <br/><br/> 
                              <font color="#F60D0D" size="4">$cmt$</font>
                              <br/><br/>
                              Details can be found below. Please note that attachments may be contained in the issue itself.
                              <br/>
                        </td>
    <tr>
                  <td style='border:none; padding:0 10pt 10pt 0'>
                              <table  border="0" cellpadding="0" cellspacing="0" style='padding:0;text-align:left;width:100%;'>
                                    <tr>
                                          <td style='width:64px;white-space:nowrap;'> </td>
                                          <td>
                                                <table>
                           
                                     <tr>
                                                      <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Issue Summary:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $summary$
                                                            </td>
                                                      </tr>
                                <tr>
                                                      <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Issue Link:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $issueLink$
                                                            </td>
                                                      </tr>
                                     <tr>
                                                      <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Issue Key:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $key$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Issue Type:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $issueType$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Assignee:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $assigneeFullName$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Created:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $cdate$
                                                            </td>
                                                      </tr>
                                                      <tr>                                                 
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Due Date:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $ddate$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Status:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $status$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Project:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  <a href=$projectLink$>project Link</a>
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Reporter:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $reporterFullName$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Last Comment:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $cmt$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Description:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $desc$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Hosts:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $host$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Reason for Change:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $reason$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Requested By:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $requested$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Group 1 Approved By:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $scadaapp$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Group 2 Approved By:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $scadaapp$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Group 3 Approved By:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $ccoapp$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Attachments:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $attachments$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Attachment Path:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $filePaths$
                                                            </td>
                                                      </tr>
                                                      <tr>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0'>
                                                                  <strong>  Subtasks:</strong>
                                                            </td>
                                                            <td bgcolor="#F1F7FA" style='border:none; padding:10 10pt 10pt 0' valign="center">
                                                                  $subt$
                                                            </td>
                                                      </tr>
                                                     
                                                     
                                                     
                                                     
                                                     
                                                </table>   
                                          </td>
                                    </tr>
                       
                </table>
                        </td>
                  </tr>
           
            <tr>
                  <td style='border:none; padding:0 10pt 10pt 0'>
                              Thanks, <br/>
                              JIRA Magic!
                        </td>
                  </tr>
                 
                  <tr>
                        <td style='border:none; padding:0 10pt 10pt 0'>
                              <div align=center>
                                    <br>
                                    This email was automatically generated by the JIRA Magic System. Please do not reply to it.
                                    <br>
                                    If you think it was sent incorrectly, please contact the Help Desk.</a>
                                    <br>
                                   
                              </div>                             
                        </td>
                  </tr>
    </table>
    </body>
</html>


Comments

Popular Posts