Page cover

๐ŸšŽCreate Jira Workflow

In this article, I would be showing you how to create Jira workflow and append transitions using go-atlassian

Step 1: Create a new Go project

Create a new directory for your project and navigate to it in your terminal or command prompt. Initialize a new Go module using the following command:

go mod init your-module-name

Step 2: Install the "go-atlassian" library

To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:

go get github.com/ctreminiom/go-atlassian

Step 3: Import the required packages

Create a new Go file, e.g., main.go, and import the necessary packages:

package main

import (
	"fmt"
	"log"

	jira "github.com/ctreminiom/go-atlassian/jira/v2"
)

Step 4: Set up Jira API client

Initialize the Jira API client with your Jira base URL and API token:

Step 5: Create a workflow

To create a new workflow, we need to the create the models.WorkflowPayloadScheme payload struct with the following information.

  1. Worfklow Name.

  2. Workflow Description.

  3. Workflow Statuses.

  4. Workflow Transitions.

Let's try to create a workflow with directed transitions and all-to-all transitions, something like this:

Step 5.1: Extract the status ID's

The first step to create a Jira workflow is recognize what's gonna be the statuses you want to use.

Statuses represent the different stages that an issue can go through in a workflow.

In this particular example, we're needed to use the following statuses:

  • Open

  • In Progress

  • QA

  • Waiting for approval

  • Escalated

  • Closed

  • Resolved

The previously code extracts the status ID's from the Jira instance and if one status is not available on the instance, it'll automatically create the statuses and append the information on the statusesAsMap variable.

With the status ID's, we can proceed with the creation of the workflow statuses payload

Step 5.2: Create the workflow transitions

With the statuses id's extracted, we can create a workflow transitions. The transitions define the paths that an issue can take from one status to another.

For example: an issue in the "Open" status can transition to the "In Progress" status when work begins on it.

There're the conditional validations needed to create a valid workflow transition:

  • include one initial transition.

  • not use the same name for a global and directed transition.

  • have a unique name for each global transition.

  • have a unique 'to' status for each global transition.

  • have unique names for each transition from a status.

  • not have a 'from' status on initial and global transitions.

  • have a 'from' status on directed transitions.

Step 5.3: Create the workflow

In conclusion, we can combine the statuses and transitions structs and create the workflow using the structs created on the previous steps.

Git Gist File

Last updated

Was this helpful?