This tutorial describes how to create a Forge app that checks Jira issues are assigned when the issue transitions. You'll do this using a Jira workflow validator.
If you prefer learning by looking at code, see the [Open Pull Requests Validator] (https://bitbucket.org/atlassian/forge-open-pull-requests-validator/) example app for a more complex use of Jira workflow validators.
This tutorial assumes you're already familiar with the basics of Forge development. If this is your first time using Forge, see Getting started first.
To complete this tutorial, you need the following:
npm install -g @forge/cli@latest
on the command line.An Atlassian cloud developer site lets you install and test your app on Confluence and Jira products set up for you. If you don't have one yet, set it up now:
You can install your app to multiple Atlassian sites. However, app data won't be shared between separate Atlassian sites, products, or Forge environments.
The limits on the numbers of users you can create are as follows:
The Atlassian Marketplace doesn't currently support cross-product apps. If your app supports multiple products, you can publish two separate listings on the Marketplace, but your app won't be able to make API calls across different products and instances/installations.
The app contains the logic to check whether an issue is assigned to someone before they work on it.
1 2forge create
The workflow validator runs when someone transitions an issue in Jira. Add a workflow validator by
declaring jira:workflowValidator
and function
modules in the manifest. The jira:workflowValidator
registers the details in Jira and the function
contains the validation logic.
In the app's top-level directory, open the manifest.yml
file.
Add a workflow validator entry under modules
.
1 2jira:workflowValidator: - key: issue-is-assigned-validator name: Issue is assigned validator description: Validates that the issue has an assignee before transitioning. function: validator
The name
and description
display in Jira when choosing a validator to add to a workflow
Connect the function
module by updating the function
module key
to be: validator
.
Your manifest.yml
should look like the following, with your value for the app ID:
1 2modules: jira:workflowValidator: - key: issue-is-assigned-validator name: Issue is assigned validator description: Validates that the issue has an assignee before transitioning. function: validator function: - key: validator handler: index.run app: id: '<your-app-id>' name: issue-is-assigned-validator
Implement the run
function to check that an issue is assigned before it transitions. The
function returns true
to allow the transition, or false
to block the transition. When a
transition is blocked, Jira displays the value of errorMessage
.
Open the src/index.js
file and delete the contents.
Create a run
function to contain the issue validation logic by adding:
1 2export const run = async ({ issue }) => { // Function code };
Retrieve information about the issue from the Jira REST API, using the runtime API.
1 2npm install @forge/api
index.js
, import the runtime API at the top of the file by adding:
1 2import api, { route } from "@forge/api";
run
function to retrieve the issue details by adding:
1 2const { key: issueKey } = issue; const response = await api.asApp().requestJira(route`/rest/api/3/issue/${issueKey}`); const issueJson = await response.json();
Return an object containing the validation result and an error message by adding:
1 2return { result: !!issueJson.fields.assignee, errorMessage: "The issue must have an assignee before transitioning." };
The result is true
if the issue has an assignee.
Your index.js
file should look like the following:
1 2import api, { route } from "@forge/api"; export const run = async ({ issue }) => { const { key: issueKey } = issue; const response = await api.asApp().requestJira(route`/rest/api/3/issue/${issueKey}`); const issueJson = await response.json(); return { result: !!issueJson.fields.assignee, errorMessage: "The issue must have an assignee before transitioning." }; };
Navigate to the app's top-level directory and deploy your app by running:
1 2forge deploy
Install your app by running:
1 2forge install
Select your Atlassian product using the arrow keys and press the enter key.
Enter the URL for your development site. For example, example.atlassian.net. View a list of your active sites at Atlassian administration.
Once the successful installation message appears, your app is installed and ready
to use on the specified site.
You can always delete your app from the site by running the forge uninstall
command.
Running the forge install
command only installs your app onto the selected product.
To install onto multiple products, repeat these steps again, selecting another product each time.
Note that the Atlassian Marketplace
does not support cross-product apps yet.
You must run forge deploy
before running forge install
in any of the Forge environments.
Start using the app by adding it as a validator in the workflow of a Jira Software company-managed project.
name
you defined in the manifest (1).
With your app installed and in your workflow, see it in action.
You'll see the following error message display.
The location of the error depends on how you transition the issue. For example, when you transition the issue using the controls on the issue view, the error displays on the issue view.
Check out an example app, continue to one of the other tutorials, or read through the reference pages to learn more.
jira-workflow-validator-custom-ui
template from the Forge CLI
for a more complex use of Jira workflow validators. This app uses custom UI to display
the user interface when creating, editing, or viewing validator configuration, and subscribes to Jira events
for failed expressions.Rate this page: