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.

Use an existing authorized test project first. Set environment variables through your shell's secure prompt or CI secret store; never commit credentials:

export XRAY_API_BASE_URL=https://jira.example.invalid
read -rsp 'Existing Jira PAT: ' XRAY_API_KEY
export XRAY_API_KEY

The hostname is a placeholder. Keep TLS certificate verification enabled and use trusted certificates. The API key option uses Jira's existing PAT authentication. Basic authentication instead uses XRAY_API_USER and XRAY_API_PASSWORD and omits --api-key-auth; never put secret values on the command line.

After confirming configuration and exclusive writer ownership:

python -m pytest -q --xray-case-config=case-config.json --xray-case-map=case-map.json --jira-xray --api-key-auth --execution=DEMO-1 --xray-create-tests --xray-single-writer

The controller checks project, execution type, permissions and creation metadata; then reuses exact matching Tests or creates missing Tests. It imports each result by its confirmed key into DEMO-1. The execution itself must already exist. Keep case-map.json durable between runs. To reuse only, omit --xray-create-tests and --xray-single-writer. A missing Test then fails closed. The single-writer flag is an explicit operating assertion, not a distributed lock.

Inspect the map locally with python -m json.tool case-map.json. For the synthetic example, the two identities might resolve to DEMO-101 and DEMO-102; actual keys come from Jira and must never be inferred from this example. Temporarily change the second expected value to 99 as shown in section 7, then run use-only:

python -m pytest -q --xray-case-config=case-config.json --xray-case-map=case-map.json --jira-xray --api-key-auth --execution=DEMO-1

Expect pytest exit 1 and two independent Test Runs: the first case's confirmed key has PASS, the second has FAIL. Repeat the same use-only command: both keys remain unchanged and no Test is created. This command imports results online; the repository's installed tutorial verifies it only against a loopback synthetic server. Inspect the selected Test Execution in your authorized environment to check its Test Runs; local fixture success is not live Xray validation.

A lost creation response leaves a pending record. Subsequent runs may reconcile one exact existing Test; zero or multiple matches block further creation. Do not remove the map or its pending entry to force a retry. Have an authorized operator reconcile the outcome and search-index visibility first. No automatic POST retries occur. Import failure may have changed the execution; inspect it before rerunning.