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.
Community moderators have prevented the ability to post new answers.
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, )
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.