Groovy templates is a templating engine for JavaScript. It lets you insert dynamic content in any text through the use of templates. A template contains variables and/or expressions, which get replaced with values when a template is rendered. This is very similar to JSP markup.
On this page:
Groovy templates in JMWE
Groovy templates in JMWE are used in:
- Comment issue and Comment linked issues post-function to create the body of the comment by selecting
Groovy template
as theComment type
- Create/Clone issue post-function to:
- Set fields of new issue by selecting
Groovy template
as theValue type
and - Add a comment to the current issue by selecting
Groovy template
as theComment type
- Set fields of new issue by selecting
- Set field value to a constant or Groovy expression and Set field value of linked issues post-functions to set a field value by selecting
Groovy template
as theValue type
- Email issue post-function to write the
Subject, HTML body and Text body
- Link issues to the current issue post-function to write
JQL search expression
Groovy templating features
To output the result of a simple Groovy code, write your Groovy code as <%= some Groovy code %>.
For example:
<%= issue.getKey() %>
To simply execute a Groovy code and not output the result, write your Groovy code as <% some Groovy code %
>. For example:
<% issue.getKey() %>
You could also use $Groovy code
, but only for a variable and not when a method is called on a variable. For example:
$currentUser()
returns an ApplicationUser
$currentUser.name
returns the name of the ApplicationUser
$currentUser.getName()
returns an error
Groovy template examples
Write the issue key as a comment to the issue:
Issue key: <%= issue.get("issuekey") %>
Comment an issue based on the priority of the issue
<% if (issue.get("priority").name == "Critical") { %> The priority of the issue is <%=issue.get("priority").name %>. So Look out! <% } %>
To send an Email to the Voters and Watchers of the issue when the issue is resolved, write this is the Subject of the Email
Hi All, <% if (issue.assignee) {%> The issue <%= issue.key%> has been resolved by <%=issue.assignee%> <%} else {%> The issue <%= issue.key%> has been resolved <%}%> Regards, <%=issue.get("project")?.getLead()?.getDisplayName()%>
Note that you can also "print" to the text: If you would like to print all the components of the project
<% issue.getAvailableOptions("components").each() { print "Component: "+ it.name + "\n" } %>