2017-07-02 71 views
1

我想了解如何使用Jenkins的REST API在JIRA中创建新门票。有什么限制或特别的事情我应该知道? 我将编写一个Python脚本,它将解析构建日志,然后在JIRA项目中创建一个新票据。使用REST api在JIRA中打开新门票

我检查了插件,但其中大多数只能更新现有的门票。 感谢

+2

只是一个正常的API调用来创建一个JIRA,不知道你的担心。 – chenrui

+0

只需选择正确的API([Cloud](https://docs.atlassian.com/jira/REST/cloud)与[Server](https://docs.atlassian.com/jira/REST/server/) )并发送带有参数化内容的POST请求到'/ rest/api/2/issue'端点。 –

回答

0

有文档here有关JSON模式和一些示例JSON这需要你的POST请求的身体去/rest/api/2/issue https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-createIssue

这是一个基本python3脚本进行POST请求

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) 

使用this HTTP请求库蟒蛇
http://docs.python-requests.org/en/master/

您可以在同一个项目中使用现有问题的ID或密钥向/rest/api/2/issue/{issueIdOrKey}/editmeta发出GET请求,因为您将通过API创建的问题将用于获取所有可以设置的字段以及哪些字段的列表是必要的。

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