我想了解如何使用Jenkins的REST API在JIRA中创建新票证。我应该注意哪些限制或特殊事项? 我将编写一个Python脚本,它将解析构建日志,然后在JIRA项目中创建一个新票证。
我查了一下插件,但大多数插件只能更新现有的门票。 感谢
答案 0 :(得分:0)
有关于JSON模式的文档here和一些示例JSON,它们需要在POST请求的主体中放到/rest/api/2/issue
https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-createIssue
这是一个发布帖子请求的基本python3脚本
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请求库进行python
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