Search code examples
jenkins-pluginsjira-rest-apijira-xray

Link a jira issue to another jira issue while exporting nunit report with XrayImportBuilder


I'm trying to export nunit result to Jira Xray using XrayImportBuilder. I need to link a jira issue to another issue and I got below error. Am I missing something? XrayImportBuilder uses v2 create enpoints "rest/api/2/issue"

ERROR: Unable to confirm Result of the upload..... Upload Failed! Status:400 Response:{"error":"Error creating Test Execution - Issue create failed! - issuelinks: Field 'issuelinks' cannot be set. It is not on the appropriate screen, or unknown."

The code I used in jenkins pipeline:

step([$class: 'XrayImportBuilder', 
    endpointName: '/nunit/multipart', 
    importFilePath: 'nunit3.xml', 
    importToSameExecution: 'true', 
    projectKey: 'AT', 
    serverInstance: jiraServerId, 
    importInParallel: 'true',
    inputInfoSwitcher: 'fileContent',
    importInfo: """{
       "fields":{
          "project":{
             "key":"AT"
          },
          "summary":"${summary}",
          "issuetype":{
             "name":"Test Execution"
          }
       },
        "update":{
          "issuelinks": [{
                  "add": {
                    "values": [
                      {
                        "type": {
                          "id": "10102"
                        },
                        "outwardIssues": [
                          {
                            "key": "AT-23"
                          }
                        ]
                      }
                    ]
                  }
                }
              ]
            
        }
    }"""
])

I tried to run without update fields it worked but I ran with update-issuelinks field it failed.

In the documentation it says > importInfo and testImportInfo must comply with the same format as the Jira issue create/update REST API format.

But it doesn't work as it is expected in the API doc.


Solution

  • First, to clarify, the Jenkins plugin is like a "wrapper" for invoking Xray REST API endpoints; it doesn't use Jira REST API endpoints. Xray itself may use internally Jira REST API endpoints (or similar APIs).

    Even though it seems possible to create a issue and link it to other issues using Jira's REST API, as long as you have the "Linked Issues" on the create screen as shown below, if you import results to Xray, using Xray API, that is not supported for the time being at least for Xray server/DC. For Xray on Jira Cloud, if you have the "linked Issues" on the mentioned screen, it should work.

    enter image description here

    For Xray server/DC

    You should only consider setting fields on the destination issue (i.e. the Test Execution that will be created) using the "fields" object in that JSON. If you wish to upload results and then link the Test Execution issue to some other issues, you'll have to make a Jira REST API request yourself after uploading the results (example). However, there's currently a limitation that inhibts the Jenkins plugin of setting a build variable with the Test Execution issue key that was created.. Therefore, this approach may not work; we could think on a workaround like getting the last Test Execution issue that was created but that would be untrustworthy. You may also reach out Xray support team and ask for an improvement in order to support this in the future.