Section | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Nunjucks in JMWE for JIRA Cloud
Nunjucks in JMWE for JIRA Cloud is used to insert information while setting a field value or creating the body of a comment by a post-function. You might want to insert issue and transition information into the value using the templating features available in Nunjucks. Some basic templating features are described in the next section, and more are documented on the Nunjucks website.
Variables
A variable looks up a value from the template context. If you want to insert the value of a variable in your template, you can use the following syntax: {{ myVar }}
. This looks up for the myVar
variable from the context and displays it. Variable names can have dots in them which look up properties, just like in javascript.
Variables available in JMWE
JMWE makes the issue, transition, linkedIssue and currentUser variables available to templates. You can access their properties using "." or "[ ]". For example, you can access the current issue key using {{issue.key}}
.
issue variable
The issue variable is used to insert data from the issue being transitioned. You can access the issue data by looking up at its properties. For example:
...
{{
now}}
returns the current date and time, e.g. 2016-09-30T13:57:23.608Z
User-defined variables
In addition to the above variables, you can also create your own variables within the template using the set Nunjucks tag. For example:
{% set x = "High" %}
sets the value of the variable x to High. You can also set the variable to an object. For example: {% set assignee = issue.fields.assignee %}
...
sprints is a custom Nunjucks filter that returns the sprints of an issue or a board. It applies to an issue object or a board ID. For an issue, it uses the first scrum board to which the issue's project belongs. It takes a an optional state or a list of comma-separated sprint states of the board as a parameter. See below the structure :
...
For example :
{{ issue | sprints () }}
returns a list of sprints. See below the structure :
{{ issue | sprints () | join("," , "name") }}
returns the names of the Sprints, separated by commas.
...
You might also want to look at Accessing the details of an issue or a transition in Nunjucks to know how to access the details of an issue or a transition.
See here for more templating features available in Nunjucks. You might also want to refer here for use cases with Nunjucks annotations.