Versions Compared

Key

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

Until 5.0.0 JMWE add-on could set a field or comment an issue using either a Raw Value or the result of a Groovy expression. Starting from 5.0.0, JMWE provides an option to include Groovy templates too. Using this you can template you can output both text and Groovy expression results togetherGroovy Template is a templating engine for JavaScript. It lets you insert dynamic content 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. 

To write a simple Groovy codeOn this page:

...

Table of Contents

...

<%= some Groovy code %>

To just execute a simple Groovy code:

Code Block
<% some Groovy code %>

...

Groovy templates in JMWE 

Groovy templates in JMWE are used in:

  • Comment issue and Comment linked related issues post-function to create the body of the comment by selecting selecting Groovy template as the  as the Comment type
  • Create/Clone issue(s) post-function to:
    • Set fields of the new issue by selecting Groovy template as the Value type and type 
    • Add a comment to the current issue by selecting selecting Groovy template as the  as the Comment type
  • Set field value to a constant or Groovy expression and Set field value of linked related issues post-functions to set a field value in the by selecting by selecting Groovy template as the  as the Value type
  • Email issue post-function to write the the Subject, HTML body and Text body
  • Link issues to the current issue post-function to write the JQL search expression

Groovy

...

templating features

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

Code Block
languagegroovy
linenumberstrue
<%= issue.getKey() %>

For single-statement expressions, you can also use the following shortcut:

Code Block
linenumberstrue
${issue.getKey()}


To simply execute a Groovy code and not output the result, write your Groovy code as <% some Groovy code %>. For example:

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

You can also output the value of a variable or its properties using $variable or $variable.someProperty. For example:

$currentUser returns an ApplicationUser

$currentUser.name returns the username of the current user

To call a method on the variable, use ${variable.method()}:

${currentUser.getName()} also returns the username of the current user

Groovy template examples

Write the issue key as a comment to the issue:

code
Code Block
languagegroovy
linenumberstrue
Issue key: <%= ${issue.get("issuekey") %>
}

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 (note that we mixed <%= %> and ${} expressions only to show how both are valid):

Code Block
languagegroovy
linenumberstrue
Hi All,
<% if (issue.get("components").each()assignee)
{%>
%>The Component:issue <%= it.name %> <br>
<% } %>

...

 issue.key%> has been resolved by <%=issue.assignee.displayName%>
<%}
else
{%>
The issue ${issue.key} has been resolved
<%}%>
Regards,
<%=issue.get("project")?.getLead()?.getDisplayName()%>

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

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