If you are a product manager or a developer working with Jira, you will need to link issues in Jira with python from time to time.
Why link issues in Jira?
Linking issues in Jira is a powerful feature that allows you to:
- Organize the work in Jira
- Track related tasks, defects, and enhancements.
In this blog post, we will dive into how to link issues in Jira with python and provide a complete code snippet that can get you started on linking issues in Jira.
The Jira python library is a tool that can be used to link issues in Jira with python. The Python library is a powerful tool that provides access to the Jira API using pre-defined python methods. It acts as an interface to manage Jira issues using python.
Install the Jira python library using pip. To do this, run the following command:
pip install jira
Once the Python library is installed, import it into the Python script and create a Jira connection object using the basic_auth protocol.
Read more about how to create a Jira connection object.
from jira import JIRA
email = '[email protected]'
api_token = 'api_token'
jira_server = 'https://server_name.atlassian.net'
jira_connection = JIRA(
basic_auth=(email, api_token),
server=jira_server
)
With the Jira instance ready, linking two issues in Jira is now possible.
we need to use the create_issue_link
method provided by the Jira python library. This method takes four arguments:
- type: Type of linking (more details about the types of links below)
- inwardIssue: The issue with linking from
- outwardIssue: The issue to link to
- comment: A comment to add to the inward issue. The comment should be a Dict containing
body
field. The body field holds the text of the comment.
Here is an example of how to use the
method to link two issues in Jira:create_issue_link
response = jira_connection.create_issue_link(
type="Relates",
inwardIssue="PJH-4",
outwardIssue="PJH-5",
comment={'body': "This is a comment explaining why the issues are linked"}
)
The
method returns a create_issue_link
response
object with status code 201(created) that contains the details of the linked issue.
Here is the complete code snippet that demonstrates how to link issues in Jira with python:
from jira import JIRA
email = '[email protected]'
api_token = 'api_token'
jira_server = 'https://server_name.atlassian.net'
jira_connection = JIRA(
basic_auth=(email, api_token),
server=jira_server
)
response = jira_connection.create_issue_link(
type="Relates",
inwardIssue="PJH-4",
outwardIssue="PJH-5",
comment={'body': "This is a comment explaining why the issues are linked"}
)
print(response)
Sample response object:

Linking issues in Jira with python is a convenient way to organize your work.
Using the python library, you can easily link issues using python.
The comprehensive code snippet provided in this guide should be a great starting point for linking issues in Jira with python.
Different types of link relationships:
Several types of link relationships can be used in Jira to link issues together:
- Blocks: This relationship indicates that one issue is blocking the progress of another issue.
- Clones: This relationship indicates that one issue is a clone of another issue.
- Depends: This relationship indicates that one issue depends on the completion of another issue.
- Duplicates: This relationship indicates that one issue is a duplicate of another issue.
- Relates: This relationship indicates that two issues are related, but there is no direct dependency.
Therefore, in the complete code snippet listed above, we can replace the Relates
relationship with any of the above types of relationships. Using the correct types of Jira relationships is a good Jira practice.
The above relationships also have counterparts. The counterparts are the reverse relationship. They are as follows:
- Is blocked by: The reverse relationship of Blocks.
- Is cloned by: The reverse relationship of Cloners
- Is dependent on: The reverse relationship of Depends
- Is duplicated by: The reverse relationship of Duplicates
- Is related to: The reverse relationship of Relates.
Automating linking issues and creating a seamless workflow for your team is possible. Using the Jira API, you can easily create and manage links between issues, such as blocking relationships, dependency relationships, and related issues. You can also use Python to automate tasks such as creating and updating issues, retrieving information about linked issues, and generating reports. Using Python to link issues on Jira can save time and effort while providing valuable insights and data to help manage and improve your projects.
Happy automating!