admin管理员组文章数量:1122826
When using JIRA with TestRail and Confluence you can link a Requirement to a ticket and you can link a TestRail Test Case to a JIRA ticket. For example:
Now using the JIRA python module it is possible to get the ticket details using a code like
from jira import JIRA
myjira = JIRA(server="/", basic_auth=(username, password))
issue = jira.issue("PROJ-1")
print(issue.raw)
and print all the details of the ticket. Unfortunately, there is no mention of the linked requirement "DALEX-REQ-001" or the TestRail TestCase "C155535"!
How can I use the JIRA API to get these two fields for the Requirement and the TestRail TestCase?
When using JIRA with TestRail and Confluence you can link a Requirement to a ticket and you can link a TestRail Test Case to a JIRA ticket. For example:
Now using the JIRA python module it is possible to get the ticket details using a code like
from jira import JIRA
myjira = JIRA(server="https://my.jiraserver.com/", basic_auth=(username, password))
issue = jira.issue("PROJ-1")
print(issue.raw)
and print all the details of the ticket. Unfortunately, there is no mention of the linked requirement "DALEX-REQ-001" or the TestRail TestCase "C155535"!
How can I use the JIRA API to get these two fields for the Requirement and the TestRail TestCase?
Share Improve this question asked Nov 22, 2024 at 12:17 AlexAlex 44.1k100 gold badges297 silver badges513 bronze badges 2- Can you check what calls is your browser doing? It should be easier that way to at least find some pointers to documentation. – Arkadiusz Drabczyk Commented Nov 26, 2024 at 20:32
- I checked my JIra Administration section on my company's account and there isn't a stock Requirements field which makes me think it is a custom field. Can you make a python rest apy call to the following JIRA REST API – Joseph Ishak Commented Nov 27, 2024 at 18:31
4 Answers
Reset to default 0To fetch data based on requirement & testRail, You can write something like this:
from jira import JIRA
myjira = JIRA(server="https://my.jiraserver.com/", basic_auth=("username", "password"))
issue = myjira.issue("PROJ-1")
print(issue.raw)
for link in issue.fields.issuelinks:
if hasattr(link, 'outwardIssue'):
print(f"Outward issue: {link.outwardIssue.key}")
if hasattr(link, 'inwardIssue'):
print(f"Inward issue: {link.inwardIssue.key}")
For testRails:
test_case = issue.fields.{customfield_12345} // add yours
As it turns out, the references are used in JIRA by a tool/plug-in named "Yogi". There is a reference for these """Yogi""" requirements HERE.
Then you have to guess how to create your query, and the following code does in deed finally return requirements information associated with a ticket:
import requests
from requests.auth import HTTPBasicAuth
# Username and Password
username = "your_username"
password = "your_password"
# Headers
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
# Complete JIRA URL
jira_url = "https://my.jira-instance.com/rest/reqs/1/issuelinks/TEST-2619"
# Make the GET request to fetch issue details
response = requests.get(
jira_url,
headers=headers,
auth=HTTPBasicAuth(username, password)
)
print(response.json())
You can fetch data by making an API call
Sample Code Snippet:
from jira import JIRA
import requests
jira = JIRA(server="https://my.jiraserver.com/", basic_auth=("username", "password"))
issue = jira.issue("PROJ-1")
# fetch fields
requirement_field = issue.fields.your_field_id
testrail_field = issue.fields.your_field_id
# TestRail API call
testrail_url = "https://my.testrailserver.com/"
headers = {"Content-Type": "application/json"}
auth = ("testrail_username", "testrail_api_key")
# fetch linked test cases
response = requests.get(
f"{testrail_url}/index.php?/api/v2/get_cases",
headers=headers,
auth=auth,
)
print(response.json())
I checked the Jira Administration section on a sample account and there isn't a stock Requirements field which makes me think it is a custom field in your cloud installation (unless your are using a server installation).
Can you clarify if you are using cloud or server impleentation? I can't tell from the url you specified if it is a hosted jira server implementation or a custom url for a cloud implementation.
If it is a cloud implementation, can you make a python rest api GET call to the following JIRA REST V3 API named field
https://sample_company.atlassian.net/rest/api/3/field
Make sure to update the url with your cloud instance or it will fail as sample_company isn't a real domain.
That will return all the fields whether they are system or custom in json format. You can then parse the json to find the field(s) once you know the field names. Here is the structure of a sample field from a sample jira cloud installation for reference
{
"id": "customfield_10072",
"key": "customfield_10072",
"name": "samplefield",
"custom": false,
"orderable": true,
"navigable": true,
"searchable": true,
"clauseNames": [
"cf[10072]"
],
"schema": {
"type": "string",
"system": "samplefield"
},
"customId":10072
},
The name
will most likely be Requirements
for the custom field you are lookiing for since that is what is rendering in the screenshot but id and key for the field will have a name such as customfield_NNNNN where the NNNNN is a custom number depending on how many custom fields you have in your installation. Once you know this id
or key
, you can make a python rest api call to the JIRA REST V3 API for your issue and get the custom field values from the previous API. This will change from customer install to customer install so I can't give the exact field.
Here is the Jira Rest API for an issue for example:
https://sample_company.atlassian.net/rest/api/3/issue/jira_ticket
where jira_ticket is the name of the jira_ticket you are trying to get the data from.
So for example if my ticket is XX-13515, I would make a GET Request to
https://sample_company.atlassian.net/rest/api/3/issue/XX-13515
That would return JSON output. You could then parse the results for the customfield_NNNN for your Requirements
field and the other field you are looking for. There could be multiple ways you would find the field in the results for your issue such as:
{
"id": "customfield_10027",
"key": "customfield_10027",
"name": "Requirements",
"untranslatedName": "Requirements",
"custom": true,
"orderable": true,
"navigable": true,
"searchable": true,
"clauseNames": [
"cf[10027]",
"Requirements",
"Requirements[Paragraph]"
],
"schema": {
"type": "string",
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:textarea",
"customId": 10027
}
},
or it could be a simple url such as
"customfield_10072": null,
or possibly some other type. So anything would else be speculation at this point without some sample results from you to investigate further.
本文标签:
版权声明:本文标题:How to get the linkreference of a "Requirement" and "Testrail: Cases" from a JIRA entry via 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303843a1932019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论