How it works...

Jira's email templates use the Apache Velocity (http://velocity.apache.org) template language to display dynamic data. Each template is a mix of static text (with or without HTML markups) and some Velocity code. If you do not need to have dynamic contents, then you can only have static text in your templates.

In our previous examples, every time you see the dollar sign ($), such as in the phrase $issue.key, it is a piece of Velocity code. The $ sign is an instruction to get a variable from the Velocity context, and the variable name is the word that comes directly after the $ sign so, in this case, it is issue. The period character (.) is an instruction to get the specified value from the variable. So, $issue.key can be read as get the value of key from the variable issue, or in other words, get me the issue's key.

Jira exposes a number of variables in its Velocity context for email templates; you can find the full list at https://confluence.atlassian.com/display/JIRA041/Velocity+Context+for+Email+Templates.

So, if we take a look at our templates, for the subject template, the ($issue.key) $issue.summary Velocity code will be turned into something like IT-10 Request for Jira administrator access, where IT-10 replaces $issue.key and Request for Jira administrator access replaces $issue.summary.

You can also have conditional logic in your Velocity templates. In our example, we have an if/else condition. We check to see if there is a comment accompanying the approve transition, and if there is, we will display the comment. If there is no comment, then we simply display No Comment in italic font.

The following screenshot shows a sample email generated from the custom template that we have created, displayed in Gmail:

Now, onto the custom Issue Approved event. Unlike system events, custom events can only be fired from workflow transitions (or custom script code), so we have to update our workflows. Every workflow transition fires an event, and by default, the Generic Event is fired. This means that most workflow transitions will have the same notification recipient using the email template.

By configuring the workflow to fire our own custom event, we have finer control over who receives notifications and which templates to use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.12.249