Versions Compared

Key

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

Introduction to Nunjucks

Nunjucks is a sophisticated 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; and tags, which control the logic of the template. See here for an overview of the templating features available in Nunjucks.

Column
width500px
Panel
borderColorsilver
bgColor#f5f5f5
borderWidth1
borderStylesolid

On this page:

Table of Contents

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 issuetransitionlinkedIssue 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 %}

...

{{ issue | sprints("active") | first | field("id") }} returns the currently active sprint ID.


isInGroup

The isInGroup filter is a custom Nunjucks filter that returns true if the user is in the specified group (passed as a parameter to the filter). The user, provided as input to the filter, can be either a username or a user object. For example:

{{ currentUser | isInGroup("jira-administrators") }} returns true if the current user is in the "jira-administrators" group.

{{ issue.fields.assignee | isInGroup("jira-servicedesk-users") }} returns true if the assignee of the issue is in the "jira-servicedesk-users" group.

isInRole

The isInRole filter is a custom Nunjucks filter that returns true if the user is in the named role (passed as a parameter to the filter). The user, provided as input to the filter, can be either a username or a user object. Expected parameters are:

    • isInRole(roleName): returns true if the user is in the named project role of the project of the current issue
    • isInRole(roleName, projectKey): returns true if the user is in the named project role of the project whose key is the specified projectKey
    • isInRole(roleName, issueObject): returns true if the user is in the named project role of the project of the given issue object

For example:

{{ currentUser | isInRole("Developers") }} returns true if the current user is in the "Developers" project role.

{{ issue.fields.reporter | isInRole("Developers","ARM") }} returns true if the current user is in the "Developers" project role of the project whose key is "ARM"

{{ currentUser | isInRole("Developers",linkedIssue) }} returns true if the current user is in the "Developers" project role of the project of the first issue linked to the current issue with 'blocks' link type.


You will find a lot more Nunjucks built-in filters here.

...

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 NunjucksYou might also want to refer here for use cases with Nunjucks annotations.