how to import junit xml file using Curl command ?

Deleted user September 23, 2022

I'm working on importing Junit XML file that i generate with my tool Cypress , and i looking for importing all test cases insides ti Jira Xray by using command CURL 

 

I tried so many input like : 

curl -H "Content-Type: multipart/form-data" -u user:pwd -F "file=@test-results.xml" https://jira.fr/rest/raven/1.0/import/execution/junit?projectKey={somekey}

curl -H "Content-Type: multipart/form-data" -u user:pwd -F "file=@test-results.xml" https://jira.fr/rest/raven/1.0/import/execution/junit/multipart?projectKey={somekey}

curl -H "Content-Type: multipart/form-data" -u user:pwd -F "file=@test-results.xml" https://jira.fr/rest/raven/1.0/import/execution/junit?testExecKey={somekey}


curl -H "Content-Type: multipart/form-data" -u user:pwd -F "file=@test-results.xml" https://jira.fr/rest/raven/1.0/import/execution/junit/multipart?projectKey={somekey}&testExecKey{somekey}

 

 

I got always those responses : 

{"error":"org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found"}

{"error":"The Test Execution info file is required."}

 

 

is there new methode to make that works please ?

 

 

1 answer

1 accepted

1 vote
Answer accepted
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 23, 2022

Hi @[deleted] and welcome to the community,

multipart import takes an xml with a json.

Did you try to use „Content-Type: text/xml“?

Best
Stefan

Deleted user September 26, 2022

yes , i did . It returns nothing . and when i go to my Test Excution Task in Jira , i find that any tests was imported .

 

this my command :

curl -H "Content-Type: text/xml" -u user:pwd -F "file=@test-results.xml" https://jira.fr/rest/raven/1.0/import/execution/junit?testExecKey=SC-{someKey}

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 26, 2022

Hi @[deleted] ,

it seems your call is missing the method (POST). This is a call I used  succeessfully in the past:

curl -H "Content-Type: text/xml" -X POST \
-H "Authorization: Bearer ${{ secrets.XRAY_TOKEN }}" \
--data @"./cypress/test-results.xml" https://xray.cloud.getxray.app/api/v2/import/execution/junit?testExecKey=${key}

 

Best
Stefan 

Deleted user September 26, 2022

 

.

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 27, 2022

Hi @[deleted] 

I have to add 2 things:

  • even though I was able to manage to import test results I´m a dev/technical rookie. So it´s not my daily business to read xml but I try to find information with documentation
  • I mainly use cloud version so I could not directly test things on server =S

 

In reference to your xml:
according to this documentation page there is a <testsuites> tag wrapped around <testsuit>

<?xml version="1.0" ?>
<testsuites>
    <testsuite errors="0" failures="0" id="0" name="my test suite" tests="1">
        <testcase classname="some.class.name" name="Test1" time="123.345000"/>
    </testsuite>
</testsuites>

 

Which test framework/reporter are u using? How is the xml-file generated?

 

Furthermore:
If you send reports (like verbose output) make sure to delete passwords/plain use names/Tokens in order to keep security level of your system.

Best
Stefan

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 3, 2022

Hi @[deleted] 

any update?

Best
Stefan

Ajay Taneja January 23, 2023

deleted

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2023

Hi @Ajay Taneja 

first of all an most important:

Please avoid posting with your real token in plain text here. 

some more questions to further specify your problem:

- which framework are you using?

- which reporter?

- is the components field a required field in your instance?

 

Best
Stefan

Ajay Taneja January 23, 2023

deleted

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2023

Hi @Ajay Taneja 

As far as my knowledge reaches there is no way to set a field directly during xml import (especially as this is a native Jira entity and not xray relevant). 

2 things coming to my mind:

either:

  • change conditions for the field (or if you running scriptrunner you could also change the required condition for the create action only with behaviours)

or:

  • just before your import run another call that creates a test execution issue and setting all the required fields (via JIRA Rest API & JSON) and then import the result file into the recently created test execution (by key).

 

Best
Stefan

Ajay Taneja January 24, 2023

Hi @Stefan Salzl 

Thanks again for the reply. I'm not setting the Component through script

I have the "Test Plan" page created and the component is already set in the Test plan page. The setting of the component is manual activity. As yous ee in my curl command, I specify:

projectKey=xxx&testPlanKey=xxxxxx

 And above the page VHS-1333 (Test Plan page) has the component set already

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2023

Hi @Ajay Taneja 

What exactly do you mean with the "Test Plan" page is create?

When you import test results it creates a test execution. This is another issue by itself (like test plan or bug or story etc...). The import invokes a create action for a test execution issue. So if the field "components" configured in the screen (issue screen scheme) to be a field in test execution the create action is checking for this field as it is required.

Best
Stefan

Ajay Taneja January 24, 2023

Hi @Stefan Salzl 

Understood. However, I'm not sure how to do this. I believe here you mean that I create a test execution issue through the XRAY REST API before the import, right?

But I'm not sure how to create a test execution issue through XRAY REST API. There will be several tests being imported. How can I create a test execution issue for each test?

  • just before your import run another call that creates a test execution issue and setting all the required fields (via JIRA Rest API & JSON) and then import the result file into the recently created test execution (by key).
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2023

Ok. Let´s take a step back.

first: As I mentioned "create issue" is a native Jira action. Therefore you have to call the Jira Rest API not the XRAY Rest API.

Usually when you import a result file it creates a test execution automatically and (if not exist) a test case issue for each test contained in the test result file (test type: generic).

 

Here is an example of one of my pipelines where I first create a sub-test-execution (via JIRA REST API) and then import my result file into this created sub-test-execution issue (via XRAY API).

key=$(

          curl --request POST \

            --url '${{ secrets.JIRA_URL }}/rest/api/3/issue' \

            --header 'Authorization: Basic ${{ secrets.TOKEN}}' \

            --header 'Accept: application/json' \

            --header 'Content-Type: application/json' \

            --data '{

              "fields": {

                "summary": "sub test execution by pipeline",

                "issuetype":

                {

                  "name": "Sub Test Execution"

                },

                "parent":

                {

                    "key": "'"${parent}"'"

                },

                "project":

                {

                  "key": "'"${project}"'"

                }

              }

            }' \

            | jq -r '.key')

         

          echo "====================================="

          echo "Sub Test Execution created with key ${key}"

          echo "====================================="

          curl -H "Content-Type: text/xml" -X POST \

          -H "Authorization: Bearer ${{ secrets.XRAY_TOKEN }}"  \

          --data @"./cypress/test-results.xml" https://xray.cloud.getxray.app/api/v2/import/execution/junit?testExecKey=${key}

 

Hope this is helpful.

Best
Stefan

Ajay Taneja January 24, 2023

Hi @Stefan Salzl 

Thank you again. I think there is a gap in understanding. I was saying, I already have an issue created. See attached. I will do this manually. I was expecting that ALL the test results in test-results.xml get imported and the test execution get created automatically.

But since the component field is required the test execution issue also expects the component field. The above script will create 1 test executions but I will have 100 test executions. IS there no possibility to avoid the "component" field in test execution?

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2023

Hi @Ajay Taneja 

but I will have 100 test executions

Even if the import would work it would create 1 test execution including all test runs. May I ask what the reason for that might be to have a test execution for each test case?

Mainly the test execution is "just" a container of test runs. A test run is an instance of a test case, an executable so to say. With requirements coverage set correctly you could always trace back which test was executed in which test execution.

 

to avoid the "component" field in test execution

there are several possibilities:

  • set the condition in your field configuration to "optional" globally or
  • create a new field configuration in which the field is optional and assiciate this field configuration to the issue type "test execution" in your field configuration scheme
  • as mentioned before: Scriptrunner behaviours (if installed) is another possibility

 

Best
Stefan

Like Ajay Taneja likes this
Ajay Taneja January 24, 2023

deleted

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2023

Hi @Ajay Taneja 

1. 

--header 'Authorization: Basic ${{ secrets.TOKEN}}' 

--> is for the JIRA REST API (as u can see the API call calls the JIRA API 2 lines later).

 

2. no you don´t have to define those. This is a script I use in my githubAction so it´s out of a yaml script where I had to declare some variables to use later in the api call.

 

3. No you don´t have to set $Component as this wouldn´t help you. Please be aware this always handles 2 different APIs - on one side the native JIRA API that is able to create an issue and on the other hand the XRAY API that can import results (and some more specific xray tasks).

Best
Stefan

Ajay Taneja January 25, 2023

Hi @Stefan Salzl 

I'm trying to follow a better option. I deleted the Component field from The Test Execution issue type. See below Figure 1

 

Now I'm trying to Create the test execution by hitting Create. I am getting same component error

There is no component in this issue type of Test Execution but for my other issue types component is mandatory

What am I doing wrong?

 

I get the same error through the API

Figure 1

 

 

Figure 2

 

Ajay Taneja January 26, 2023

Hi @Stefan Salzl , I'm happy to inform that my problem has been sorted - 

I asked the admin to create a  new field configuration in which the field is optional and associate this field configuration to the issue type "test execution" in the field configuration scheme

And everything fell in place - you had suggested this above

 

Thank you for the help, you have been great

Like Stefan Salzl likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2023

Hi @Ajay Taneja 

I mentioned this 2 posts before:

    • set the condition in your field configuration to "optional" globally or

If the configuration "required" is set in the custom field settings (global settings) it IS required (even if it doesn´t appear on your screen). The system says: it is required therefore it asks for the field. 

Please see my suggestions above how it could be solved.

Best
Stefan

Like Ajay Taneja likes this
Ajay Taneja January 26, 2023

@Stefan Salzl it is solved, thanks a lot.

Like Stefan Salzl likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2023

Hi @Ajay Taneja ,

AWESOME!!! So great to hear you got that working.

Please consider to hit the "Accept answer" button in order to mark this issue as solved. This will make it easier for other users to find a solution in case they are faced with the same/similar problem.

Best
Stefan

Like Ajay Taneja likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events