How do I add a component to an issue using jira-python?

Sorin Sbarnea (Citrix)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2013

How do I add a component to an issue using python-jira?

Assuming that I have the component name and the issue key, how do I add this component to the issue.

The issue may already have a compoment assigned to it and I do not want to loose it.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Optiver US Admin January 5, 2014

Below is how I was able to use jira-python to create and issue and add a component. I figured this out by taking a look at the REST API for JIRA. :

jira.create_issue(project={'key': project_id}, summary=ticket_summary,
                                     description=ticket_description, issuetype={'name': ticket_issue_type},
                                     components=[{'name': 'Application Slow'},], parent={'id': new_issue_key}, customfield_10101=termination_change_date,
                                     )

1 vote
MathewI October 10, 2013

I don't believe they have built this into the API. If they have, I'm not sure if the syntax would be any more managable than a straight-up REST call

Using the requests module:

#!/usr/bin/python

import requests

auth=requests.auth.HTTPBasicAuth(USERNAME, PASSWORD)
component = 'COMPONENT'
url='http://YOUR.JIRA.URL'
issueKey='PROJECT-001'
headers={'Content-Type': 'application/json'}

params = '{"update" : {"components" : [{"add" : {"name" : "%s"}}]}}' % component
restUrl = '%s/rest/api/2/issue/%s' % (url, issueKey)
response = requests.put(restUrl, data=params, auth=auth, headers=headers)

TAGS
AUG Leaders

Atlassian Community Events