Hi. I was successfull to transition my issues from different states but I'm facing problems to transition them when it validates if I have uploaded an attachment.
I tried uploading the file before transition it but didn't work.
I did my research but couldn't figure out if is this possible to do, and if it is, how. Plese help!
from jira import JIRA
import requests
from requests.auth import HTTPBasicAuth
attachLocation = "C:\\Users\\ivan\\attachments\\"
attachFile = "text.txt"
attachmentURL = attachLocation+attachFile
parentCH = "CH-10101"
def upload_attachment (ch_issue_key, attachment, fname):
with open(attachment, 'rb') as attachment:
url = "https://mycompany.jira.com/rest/api/2/issue/" + ch_issue_key + "/attachments"
file = {"file": (fname, attachment, "application/octet-stream")}
auth = HTTPBasicAuth('ivan', 'xxxxxxxxxxxxxxx')
headers = {
"content-type": None,
"X-Atlassian-Token": "no-check"
}
r = requests.post(
url,
auth=auth,
files=file,
headers=headers
)
print(" status_code:", r.status_code)
print("\n ",r.text)
jira = JIRA(
server="https://mycompany.jira.com/",
basic_auth=('ivan','xxxxxxxxxxxxxxx')
)
issue_parent_ch = jira.issue(parentCH)
print(issue_parent_ch.fields.status) # This prints the issue status before transitioning it
status = str(issue_parent_ch.fields.status)
if status == "Completed":
upload_attachment(issue_parent_ch.key, attachmentURL, attachFile)
evidence = { "customfield_24678": "Closing issue" }
transition = 111
jira.transition_issue(issue_parent_ch.key, transition, fields=evidence)
print(issue_parent_ch.key + ": Moving from \"Complete\" to \"Start review\"")