Skip to content

4. Authenticate and publish to Jira/Xray

Continue from 3. Preview the Jira/Xray import. Use the same xray-demo folder and activated environment.

Publish the reviewed result into Jira/Xray. This step makes the integration request; the preceding payload preview did not contact the server. Start with an authorized disposable test project and existing credentials; no credentials or private test data need to be shared with the maintainer.

Prepare the two issue keys

  1. Choose an existing sandbox Jira Generic Test issue. Replace DEMO-1 in the marker with its key.
  2. Choose an existing sandbox Test Execution, for example DEMO-100. You will pass that key as --execution.
  3. Preview the intended upload with the command below. Replace DEMO-100 with your chosen execution key. Keep --xraypath=xray.json: this preview is local.
python -m pytest -q test_example.py --jira-xray --execution=DEMO-100 --allow-duplicate-ids --xray-parameter-details --xray-case-report=cases.json --xray-full-report=full-xray.json --xraypath=xray.json
python -m json.tool xray.json

Expect 2 passed. Check testExecutionKey matches the intended execution, tests[0].testKey matches your Test marker, and comment contains the case details you intend to send. This uses the normal comment limit, not the archive recipe's deliberately small demonstration limit. No credentials are required for this file export.

The two keys are not interchangeable: one identifies the Test; the other selects where its result goes.

Configure Server or Data Center authentication

This example uses an existing personal access token and Bash. It reads the token without placing it in shell history:

export XRAY_API_BASE_URL='https://jira.example.invalid'
read -r -s -p 'Existing sandbox Jira token: ' XRAY_API_KEY
printf '\n'
export XRAY_API_KEY

Replace the .invalid URL with the authorized sandbox base URL. Include Jira's context path, if it has one, but do not append a REST endpoint. The plugin adds /rest/raven/2.0/import/execution itself.

XRAY_API_BASE_URL tells the plugin where Jira is. XRAY_API_KEY holds the token; --api-key-auth below selects that authentication method. In CI, inject these through protected environment variables rather than committing them to files.

Upload the result

Use the same passing test file. This time remove --xraypath:

python -m pytest -q test_example.py --jira-xray --api-key-auth --execution=DEMO-100 --allow-duplicate-ids --xray-parameter-details --xray-case-report=cases.json --xray-full-report=full-xray.json

Replace DEMO-100 with your chosen execution key. The new options select token authentication and an existing Test Execution. Keep --cloud off for Server/Data Center.

On successful import, pytest prints the returned Test Execution ID. In Jira, open that Test Execution and the Test Run for your Test. Expect one aggregate result and comment text with case details, not native per-input iteration rows. The two local report files remain available for inspection.

When finished with this Bash session:

unset XRAY_API_KEY

Omitting --execution asks Xray to create a new Test Execution, subject to its required fields and permissions. Start with an explicit disposable execution so you know what is being updated. Reimports can replace existing Test Run details, including dataset/iteration information; inspect a run before retrying a timeout. Imports are not retried automatically because the server might already have accepted the first request. This replacement behavior is documented in the official Server/DC import API.

This command targets an existing Generic Test using the aggregate comment fallback. It does not set or change the Test type, and Generic targeting does not enable native iteration rows or datasets. See the compatibility section below for the tested versions and limits.