简体   繁体   中英

getting error on updating assignee and comment field in JIRA using python

I am using python to automate JIRA process, while doing I am unable to update Assignee and Comment fields.

While updating Assignee field, not getting any error, but the value is not updated properly, I am trying to assign from one user to other user, but it is getting updated as Unassigned

For comment field, getting an error.

Below is my code:

from atlassian import Jira
jira_instance = Jira(
    url = "https://****.atlassian.net/",
    username = "****@gmail.com",
    password = "*******",
)

data = jira_instance.jql("project = PROJECTNAME AND status = 'IN PROGRESS' ORDER BY created ASC", fields=['description','assignee','reporter','comment'])

for i in range(len(data["issues"])):
    test_data = data["issues"][i]
    jira_instance.issue_update(test_data['key'], fields={'assignee':{'emailAddress': '####@gmail.com' }})
    jira_instance.issue_update(test_data['key'], fields={'comment':{'comments': [{'body':'This is the comment'}]}})

Also tried using displayName instead of using emailAddress , but still same thing happens.

For comment field, got the below error:

Traceback (most recent call last):
  File "c:/Users/path/jiratest.py", line 13, in <module>
    jira_instance.issue_update(test_data['key'], fields={'comment':{'comments': [{'body':'This is the comment'}]}})
  File "C:\Users\path\AppData\Local\Programs\Python\Python37\lib\site-packages\atlassian\jira.py", line 891, in issue_update
    return self.put(url, data={"fields": fields})
  File "C:\Users\path\AppData\Local\Programs\Python\Python37\lib\site-packages\atlassian\rest_client.py", line 341, in put
    absolute=absolute,
  File "C:\Users\path\AppData\Local\Programs\Python\Python37\lib\site-packages\atlassian\rest_client.py", line 236, in request
    self.raise_for_status(response)
  File "C:\Users\path\AppData\Local\Programs\Python\Python37\lib\site-packages\atlassian\jira.py", line 3705, in raise_for_status
    raise HTTPError(error_msg, response=response)
requests.exceptions.HTTPError

Please anyone help me out on this

For adding a comment field, try something like this:

jira_instance.issue_add_comment(test_data['key'], 'This is the comment')

For updating the assignee, try this:

jira_instance.update_issue_field(test_data['key'], fields={"assignee": "####"})

You haven't said if you're using Jira Cloud or Server.

For Jira Cloud, you must set the assignee for an issue using that person's account ID, not their username or email address, so the request would look something like:

jira_instance.issue.update(assignee={'accountId': '5b10ac8d82e05b22cc7d4ef5'})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM