1

I'd like to understand how to create a new ticket in JIRA using REST API from Jenkins. Is there any limitations or special things I should be aware of? I'm going to write a Python script, which will parse the build log and then create a new ticket in JIRA project.

I checked the plugins, but most of them only can update the existing tickets. Thanks

Tamir Gefen
  • 1,128
  • 2
  • 18
  • 35
Tester
  • 11
  • 2
  • 2
    Just a normal API call to create a JIRA, not sure what is your concern. – chenrui Jul 02 '17 at 21:07
  • Just choose the correct API ([Cloud](https://docs.atlassian.com/jira/REST/cloud) vs. [Server](https://docs.atlassian.com/jira/REST/server/)) and send a POST request with the parametrized content to the `/rest/api/2/issue` endpoint. – Lukas Körfer Jul 04 '17 at 23:00

1 Answers1

0

There's documentation here about the JSON schema and some example JSON which needs to go in the body of your POST request to /rest/api/2/issue https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-createIssue

Here's a basic python3 script to make a post request

import requests, json
from requests.auth import HTTPBasicAuth

base_url  = "myjira.example.com"    # The base_url of the Jira insance.
auth_user = "simon"                 # Jira Username
auth_pass = "N0tMyRe3lP4ssw0rd"     # Jira Password
url       = "https://{}/rest/api/2/issue".format(base_url)

# Set issue fields in python dictionary. See docs and comment below regarding available fields
fields = {
    "summary": "something is wrong"
}

payload = {"fields": fields}
headers = {"Content-Type": "application/json"}
response = requests.post(
    url,
    auth=(auth_user, auth_pass),
    headers=headers,
    data=json.dumps(payload))
print("POST {}".format(url))
print("Response {}: {}".format(response.status_code, response.reason))

_json = json.loads(response.text)

Using this HTTP requests library for python
http://docs.python-requests.org/en/master/

You can make a GET request to /rest/api/2/issue/{issueIdOrKey}/editmeta using the id or key of existing issue in the same project as the issue's you will be creating via the API will go to in order to get a list of all the fields you can set and which ones are required.

https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-getEditIssueMeta

Simon Merrick
  • 732
  • 4
  • 13