In this article by Patrick Li, author of the book Jira 7 Administration Cookbook – Second Edition, we will take a look at how Workflows are one of the core and most powerful features in JIRA. They control how issues in JIRA move from one stage to another as they are worked on, often passing from one assignee to another. For this reason, workflows can be thought of as the life cycle of issues.
In this article, we will cover:
Unlike many other systems, JIRA allows you to create your own workflows to resemble the work processes you may already have in your organization. This is a good example of how JIRA is able to adapt to your needs without your having to change the way you work.
(For more resources related to this topic, see here.)
A workflow is similar to a flowchart, in which issues can go from one state to another by following the direction paths between the states. In JIRA’s workflow terminology, the states are called statuses, and the paths are called transitions. We will use these two major components when customizing a workflow.
In this recipe, we will create a new, simple workflow from scratch. We will look at how to use existing statuses, create new statuses, and link them together using transitions.
The first step is to create a new skeleton workflow in JIRA, as follows:
The following screenshot explains some of the key elements of the workflow designer:
As of now, we have created a new, inactive workflow. The next step is to add various statuses for the issues to go through. JIRA comes with a number of existing statuses, such as In Progress and Resolved, for us to use:
You can type the status name into the field, and JIRA will automatically find the status for you.
Once you add the statuses to the workflow, you can drag them around to reposition them on the canvas. We can also create new statuses, as follows:
JIRA will let you know if the status you are entering is new by showing the text (new status) next to the status name.
Now that we have added the statuses, we need to link them using transitions:
You should finish with a workflow that looks similar to the following screenshot:
At this point, the workflow is inactive, which means that it is not used by a project, and you can edit it without any restrictions. Workflows are applied on a project and issue-type basis. Perform the following steps to apply the new workflow to a project:
After we apply the workflow to a project, the workflow is placed in the active state. So, if we now create a new issue in the target project of the selected issue type, our new Simple Workflow will be used.
When users execute a workflow transition, we have an option to display an intermediate workflow screen. This is a very useful way to collect some additional information from the user. For example, the default JIRA workflow will display a screen for users to select the Resolution value when the issue is resolved.
Issues with resolution values are considered completed. You should only add the Resolution field to workflow screens that represent the closing of an issue.
We need to have a workflow to configure, such as Simple Workflow, which was created in the previous recipe. We also need to have screens to display; JIRA’s out-of-the-box Workflow screen and Result Issue screen will suffice, but if you create your own screens, those can also be used.
Perform the following steps to add a screen to a workflow transition:
If you are working with a draft workflow, you must click on the Publish Draft button to apply our changes to the live workflow.
If you do not see your changes reflected, it is most likely that you forgot to publish your draft workflow.
Often, you will have transitions that need to be made available from several different statuses in a workflow, such as the Resolve and Close transitions. In other words, these are transitions that have a common destination status but many different originating statuses.
To help you simplify the process of creating these transitions, JIRA lets you reuse an existing transition as a common transition if it has the same destination status.
Common transitions are transitions that have the same destination status but different originating statuses.
A common transition has an additional advantage of ensuring that transition screens and other relevant configurations, such as validators, stay consistent. Otherwise, you would have to constantly check the various transitions every time you make a change to one of them.
Perform the following steps to create and use common transitions in your workflow:
Refer to the Using global transitions recipe.
While a common transition is a great way to share transitions in a workflow and reduce the amount of management work that would otherwise be required, it has the following two limitations:
As your workflow starts to become complicated, explicitly creating the transitions becomes a tedious job; this is where global transitions come in.
A global transition is similar to a common transition in the sense that they both share the property of having a single destination status. The difference between the two is that the global transition is a single transition that is available to all the statuses in a workflow.
In this recipe, we will look at how to use global transitions so that issues can be transitioned to the Frozen status throughout the workflow.
As usual, you need to have a workflow you can edit. As we will demonstrate how global transitions work, you need to have a status called Frozen in your workflow and ensure that there are no transitions linked to it.
Perform the following steps to create and use global transitions in your workflow:
The following screenshot depicts the preceding steps:
After the global transition is added to the Frozen status, you will be able to transition issues to Frozen regardless of its current status.
You can only add global transitions in the Diagram mode.
Refer to the Restricting the availability of workflow transitions recipe on how to remove a transition when an issue is already in the Frozen status.
Workflow transitions, by default, are accessible to anyone who has access to the issue. There will be times when you would want to restrict the access to certain transitions. For example, you might want to restrict access to the Freeze Issue transition for the following reasons:
To restrict the availability of a workflow transition, we can use workflow conditions.
For this recipe, we need to have the JIRA Suite Utilities add-on installed. You can download it from the following link or install it directly from Universal Plugin Manager:
https://marketplace.atlassian.com/plugins/com.googlecode.jira-suite-utilities
We need to create a new custom field configuration scheme in order to set up a new set of select list options. Perform the following steps for this:
This means that it should only show the transition if the issue’s status field’s value is not Frozen.
At this point, we added the condition that will make sure the Freeze Issue transition is not shown when the issue is already in the Frozen status. The next step is to add another condition to restrict the transition and is only available to users in the Developer role.
After you apply the workflow conditions, the Frozen transition will no longer be available if the issue is already in the Frozen status and/or the current user is not in the Developer project role.
Using the Value Field condition (that comes with the JIRA Suite Utilities add-on) is one of the many ways in which we can restrict the availability of a transition based on the issue’s previous status. There is another add-on called JIRA Misc Workflow Extensions (this is a paid add-on), which comes with a Previous Status condition for this very use case. You can download it from https://marketplace.atlassian.com/plugins/com.innovalog.jmwe.jira-misc-workflow-extensions.
When you have more than one workflow condition applied to the transition, as in our example, the default behavior is that all the conditions must pass for the transition to be available.
You can change this so that only one condition needs to pass for the transition to be available by changing the condition group logic from All of the following conditions to Any of the following conditions, as shown in the following screenshot:
For workflow transitions that have transition screens, you can add validation logic to make sure what the users put in is what you are expecting. This is a great way to ensure data integrity, and we can do this with workflow validators.
In this recipe, we will add a validator to perform a date comparison between a custom field and the issue’s create date, so the date value we select for the custom field must be after the issue’s create date.
For this recipe, we need to have the JIRA Suite Utilities add-on installed. You can download it from the following link or install it directly using Universal Plugin Manager:
https://marketplace.atlassian.com/plugins/com.googlecode.jira-suite-utilities
As we will also do a date comparison, we need to create a new date custom field called Start Date and add it to the Workflow screen.
Perform the following steps to add validation rules during a workflow transition:
After we add the validator, if we now try to select a date that is before the issue’s create date, JIRA will prompt you with an error message and stop the transition from going through, as shown in the following screenshot:
Validators are run before the workflow transition is executed. This way, validators can intercept and prevent a transition from going through if one or more of the validation logics fail.
If you have more than one validator, all of them must pass for the transition to go through.
JIRA allows you to perform additional tasks as part of a workflow transition through the use of post functions. JIRA makes heavy use of post functions internally; for example, with the out-of-the-box workflow, when you reopen an issue, the resolution field value is cleared automatically.
In this recipe, we will look at how to add post functions to a workflow transition. We will add a post function to automatically clear out the value stored in the Reason for Freezing custom field when we take it out of the Frozen status.
By default, JIRA comes with a post function that can change the values for standard issue fields, but as Reason for Freezing is a custom field, we need to have the JIRA Suite Utilities add-on installed.
You can download this from the following link or install it directly using Universal Plugin Manager:
https://marketplace.atlassian.com/plugins/com.googlecode.jira-suite-utilities
Perform the following steps to add processing logic after a workflow transition is executed:
With the post function in place, after you execute the transition, the Reason for Freezing field will be cleared out. You can also note from the issue’s change history as a part of the transition execution that where the Status field is changed from Frozen to Open, the change for the Reason for Freezing field is also recorded.
Post functions are run after the transition is executed. When you add a new post function, you might notice that the transition already has a number of post functions preadded; this is shown in the screenshot that follows.
These post functions are system post functions that carry out important internal functions, such as keeping the search index up to date. The order of these post functions is important.
Always add your own post functions at the top of the list.
For example, any changes to issue field values, such as the one we just added, should always happen before the Reindex post function, so by the time the transition is completed, all the field indexes are up to date and ready to be searched.
In this article, you learned about not only how to create workflows with the new workflow designer but also how to use workflow components, such as conditions and validators, to add additional behavior to your workflows. We also looked at many different add-ons that are available to expand the possibilities of what you can do with workflows.
Further resources on this subject:
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…