Create Confluence pages from Jira transitions with REST calls

This page is about Easy Integrations for Jira DC. Using Jira Cloud? Click the Cloud button above.

Easy Integrations allows you to automatically generate Confluence pages based on Jira workflow transitions. This document guides you through configuring the Create Confluence Page using a template page post function.

Step 1: Add the post function

  1. Go to the desired transition of your workflow, switch to the Post functions tab, and click the Add post function link.

  2. Locate the EIS - Create Confluence Page using a template page post function. 

  3. Click on the Add button.

Step 2: Post function name

  1. Give your post function a descriptive name.

Step 3: Create script condition

  1. You can create a decision to execute the REST according to the result of Groovy script. By default, it can only return true statement. However, you can type your script and return true; to execute REST, or return false; to not execute. Here is a sample code of how you can type your own script:

Condition code example:

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.ApplicationUser ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser log.info("current user:" + currentUser.username) def reporter = issue.reporter.username log.info("reporter: " + reporter) return reporter.equals(currentUser.username)

Step 4: Fill in REST service details

  1. In this section, REST details are filled.

  2. URL – The endpoint of the REST service. You can type any dynamic parameter here using double curly braces (e.g. http://mycompany.com/api/book/{{bookId}} assuming bookId is defined in the Parameters section which is described below).

  3. Method – Select Http Method (GET, POST, PUT, DELETE).

  4. Headers – Define your HTTP header key/value sets on separate lines as shown in the screenshot.

  5. Request Body – Type json request body. You can use dynamic parameters here as well.

{ "assignee" : "{{assignee}}", "reporter" : "{{reporter}}", "userName" : "{{userDisplayName}}", "price" : "{{price}}" }
  1. Parameters: Define all of your dynamic parameters here using Groovy Script. You can add static values as well as the dynamic values of fields/custom fields in the Jira issue. Here are some sample usages:

def parameters = [:] parameters["assignee"] = issue.assignee parameters["reporter"] = issue.reporter def userManager = ComponentAccessor.getUserManager() parameters["userDisplayName"] = userManager.getUserByName("someUserName").getDisplayName() def cf = customFieldManager.getCustomFieldObject("customfield_xxxxx") def price = issue.getCustomFieldValue(cf) parameters["price"] = (null != price) ? price : "No price defined" return parameters

For more details about parameter assigning and utils, see the Parameters Usage Examples page.
Also see the ComponentAccessor, UserIssueand Status API pages for all properties and methods.

  1. Authorization Type: Choose authorization type - currently BASIC Authentication is supported.

  2. Credential: If you choose any Authorization Type, this option becomes active and the credentials you defined in the Credentials section will be listed. Below is an example:

Step 5: Configure a post function (Optional)

In this section, you can configure the post function to update a custom field based on a value in the REST response.

  1. Check the Update custom field box to update a custom field based on the REST response.

  2. Select the custom field you want to update from the dropdown.

  3. Enter a JSONPath expression to specify the value within the response to update the field with. Leave empty if you want to use the entire response body. For JSONPath examples, see the JSONPath examples page.

Step 6: Run asynchronously (Optional)

In this section, you can enable async to execute the REST service asynchronously. There are a couple of reasons why you may want to execute asynchronously:

  • Executing synchronously makes the user wait for the transition longer than usual. If the REST service host responds late or there is a connection timeout between the Jira server and the host, the user will wait for the spinner for a long time. So, it may be wise to enable async if your REST service responds slowly.

  • Some issue parameters may wait for calculation or reindexing. Some plugins may work in the background to populate the actual result of a custom field and you may want to use that value. 

A scheduled task titled Easy Integrations for Jira - Async Rest Caller Scheduled Task is set to run every 2 minutes. This task is responsible for monitoring specific REST calls and carrying out the necessary executions.

Step 5: Publish the workflow

  1. Save your changes to the workflow.

  2. Publish the workflow for the changes to take effect.

Order of execution

The order of the REST Service Caller post function is very important and depends on what you want to do. 

If the REST Service Caller post function is BEFORE the Update change history for an issue and store the issue in the database post function:

  • $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123')) call returns the old value of customfield_10123.

  • $transientIssue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123')) call returns the new value of customfield_10123.

  • If the Update custom field is selected, the custom field(s) will be updated successfully.

If the REST Service Caller post function is AFTER the Update change history for an issue and store the issue in the database post function:

  • $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_10123')) call returns the new value of customfield_10123.

  • If the Update custom field is selected, the custom field(s) will not be updated successfully as the Update change history and store the issue in the database post function is already executed.