Versions Compared

Key

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

Groovy template Template is a templating engine for JavaScript. It lets you insert dynamic content in into 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. 

...

Groovy templating features

To output the result of a simple Groovy codeexpression, write your Groovy code as <%= some Groovy code %>. For example:

...

Code Block
languagegroovy
linenumberstrue
<% issuelog.getKey(debug("I was here") %>

You could also use $some Groovy code, but only for a variable and not when a method is called on a variablecan also output the value of a variable or its properties using $variable or $variable.someProperty. For example:

$currentUser() returns  returns an ApplicationUser

$currentUser.name returns the name of the ApplicationUser

However, calling methods is not supported:

$currentUser.getName() returns an errorerror 

Groovy template examples

Write the issue key as a comment to the issue:

...

Comment an issue based on the priority of the issue:

Code Block
languagegroovy
linenumberstrue
<% 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 as the Subject of the Email:

Code Block
languagegroovy
linenumberstrue
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()%>

(info)(info) Note that you can also "print" to the text: If you would like to print the components of the project:

Code Block
<% issue.getAvailableOptions("components").each() {
  print "Component: "+ it.name + "\n"
}
%>

...