Import test results into Jira from your CI pipeline
Jira can’t read a JUnit or Cucumber report on its own. What it shows natively, a pipeline step that posts results, and how test management apps record each run.
Jira can’t read a test report by itself. It has nowhere to keep a result per test, so getting JUnit XML, Cucumber JSON or TestNG output into Jira always takes one extra step in your pipeline: a script that calls Jira’s REST API, an automation flow that receives a webhook, or a test management app with an import endpoint.
This guide covers the formats and CI tools most teams use, what Jira shows without help, a working step for GitHub Actions with its equivalents in GitLab CI, Jenkins and Bitbucket Pipelines, and how a test management app records each run.
The report formats your tests already write
| Format | Written by | What one result holds |
|---|---|---|
| JUnit XML | JUnit, Maven Surefire, Gradle, pytest, Jest (with jest-junit) and most other runners | A testcase element with a classname and a name, plus a failure, error or skipped element when it didn’t pass |
| Cucumber JSON | Cucumber’s json formatter |
Features, then scenarios, then steps, each step with its own status |
| TestNG XML | TestNG’s testng-results.xml |
A test-method element with a status of PASS, FAIL or SKIP |
JUnit XML is the common format. GitLab, Jenkins and Bitbucket Pipelines all read it to show test results, Cucumber has a JUnit formatter, and TestNG suites run through Maven Surefire or Gradle write it too. If you can, make every suite write JUnit XML and convert one format instead of three.
What Jira shows without help
Connect GitHub, GitLab, Bitbucket or Jenkins (through the Jenkins for Jira app) and a work item’s Development panel lists its branches, commits, pull requests, builds and deployments. A build shows up on a work item when its branch name or a commit message contains the work item key, such as SHOP-142. Atlassian lists the details in what development data you can view in Jira.
That tells you whether a build passed. It doesn’t tell you which tests failed, keep a history per test, or connect a failure to a test case or a requirement. Jira’s builds data has room for a count of passed, failed and skipped tests, and nothing finer. Teams that try to push test runs through Jira’s REST API alone hit the same wall, as this Community question shows: the API creates work items, but has nowhere to put steps or results. Anything more, you add yourself.
Post results to a work item with the REST API
The simplest useful setup: after the tests run, read the JUnit files and post a comment with the totals on the work item named in the branch.
-
Create an API token for the account the pipeline will use. In your Atlassian account, open API tokens, select Create API token and choose an expiry date. Save the account’s email address and the token as CI secrets.
-
Add a script to the repository that lists every test with its result:
# scripts/junit_results.py: prints [{"name": ..., "status": ...}] for every test case import glob, json, sys import xml.etree.ElementTree as ET def status(case): for tag, result in (("failure", "failed"), ("error", "error"), ("skipped", "skipped")): if case.find(tag) is not None: return result return "passed" rows = [ {"name": f'{case.get("classname")}.{case.get("name")}', "status": status(case)} for path in glob.glob(sys.argv[1], recursive=True) for case in ET.parse(path).iter("testcase") ] print(json.dumps(rows, indent=2)) -
Add a step after the tests that runs even when they fail, finds the work item key in the branch name, and posts the comment:
- name: Post test results to Jira if: ${{ !cancelled() }} env: JIRA_SITE: https://acme.atlassian.net JIRA_USER: ${{ secrets.JIRA_USER }} JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} BRANCH: ${{ github.head_ref || github.ref_name }} run: | python3 scripts/junit_results.py "build/test-results/**/*.xml" > results.json PASSED=$(jq '[.[] | select(.status == "passed")] | length' results.json) FAILED=$(jq '[.[] | select(.status == "failed" or .status == "error")] | length' results.json) SKIPPED=$(jq '[.[] | select(.status == "skipped")] | length' results.json) RUN_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" KEY=$(echo "$BRANCH" | grep -oE '[A-Z][A-Z0-9]+-[0-9]+' | head -n 1) if [ -n "$KEY" ]; then jq -n --arg body "CI on $BRANCH: $PASSED passed, $FAILED failed, $SKIPPED skipped. $RUN_URL" '{body: $body}' | curl -sS --fail-with-body -X POST -u "$JIRA_USER:$JIRA_API_TOKEN" \ -H "Content-Type: application/json" --data @- \ "$JIRA_SITE/rest/api/2/issue/$KEY/comment" fi
The endpoint is Add comment, POST /rest/api/2/issue/{issueIdOrKey}/comment. Version 2 of the API takes the comment as plain text in body; version 3 expects the same field in Atlassian Document Format, a JSON tree of paragraphs and text nodes. To open a work item instead of commenting, send POST /rest/api/2/issue with the space key, a work type and a summary:
{"fields": {"project": {"key": "SHOP"}, "issuetype": {"name": "Bug"}, "summary": "3 tests failed on main"}}
The same step in other CI tools:
| CI tool | Run the step after failed tests | Keep the token in |
|---|---|---|
| GitHub Actions | if: ${{ !cancelled() }} on the step |
Repository or environment secrets |
| GitLab CI | after_script, or a later job with when: always |
Masked CI/CD variables |
| Jenkins | A post { always { ... } } block |
Credentials, bound with withCredentials |
| Bitbucket Pipelines | after-script |
Secured repository variables |
Or let a Jira automation flow receive them
If you’d rather not keep a Jira API token in CI, an automation flow (Jira’s name for an automation rule) can take the results. It gets a URL and a secret of its own.
-
Go to Space settings > Automation, select Create flow, then Create from scratch.
-
Choose the Incoming webhook trigger and set it to run without work items from the webhook, since the flow creates its own.
-
Add a Create work item action with work type Bug, the summary
{{webhookData.failed}} tests failed on {{webhookData.branch}}, and{{webhookData.url}}in the description. -
Turn the flow on, then open the trigger and copy its URL and secret. In the pipeline step above, replace the
ifblock that posts the comment with one that posts only when something failed:if [ "$FAILED" -gt 0 ]; then jq -n --arg branch "$BRANCH" --arg url "$RUN_URL" --argjson failed "$FAILED" \ '{branch: $branch, failed: $failed, url: $url}' | curl -sS -X POST "$JIRA_WEBHOOK_URL" \ -H "Content-Type: application/json" \ -H "X-Automation-Webhook-Token: $JIRA_WEBHOOK_SECRET" \ --data @- fiAdd
JIRA_WEBHOOK_URL: ${{ secrets.JIRA_WEBHOOK_URL }}andJIRA_WEBHOOK_SECRET: ${{ secrets.JIRA_WEBHOOK_SECRET }}to the step’senv.
Every field in the JSON body is available under {{webhookData}}. Atlassian covers the setup in configure the incoming webhook trigger. Each run uses part of your site’s automation allowance, so a flow that fires on every build adds up.
Where both fall short
- You get totals and a link, not a result per test. Nobody can ask Jira which tests failed in the last five runs.
- Nothing ties a failure to a test case or to the requirement it covers, so coverage can’t be worked out.
- A comment per build buries the work item’s history, and a Bug per failure floods the backlog.
- Renamed and deleted tests leave no trace.
How test management apps handle it
A test management app gives results a home: a test case for each test, and a test execution (a run) that records one result per case. Many offer an endpoint the pipeline posts to after the tests. Xray, for example, accepts JUnit XML, TestNG XML, Cucumber JSON and several other formats on its import endpoints. Others take a JSON summary that your pipeline builds from the report. Either way, each result has to find its test case, usually by a key or name that you keep stable in the test code.
Record CI runs with Advanced Test Management
Advanced Test Management for Jira takes a JSON summary of each run and turns it into a completed Test Execution. The automation import needs three things:
-
On the app’s Automation tab, copy the space’s Import URL, and have a space admin select Generate token. The token is shown once, so store it as a CI secret.
-
Give each Test Case an Automation Key that matches what your tests report under. With the script above, that’s the class and test name, such as
checkout.GuestCheckoutTest.declinedCardKeepsCart. -
Post the results. The script’s statuses (
passed,failed,skippedanderror) are the ones the import accepts:jq --arg run "gh-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" --arg sha "$GITHUB_SHA" '{ externalRunId: $run, projectKey: "SHOP", source: "github-actions", environment: "staging", build: $sha, rows: map({automationKey: .name, status: .status}) }' results.json | curl -sS -X POST "$ATM_IMPORT_URL" \ -H "Content-Type: application/json" -H "X-TMF-Token: $ATM_TOKEN" --data @-Add
ATM_IMPORT_URL: ${{ secrets.ATM_IMPORT_URL }}andATM_TOKEN: ${{ secrets.ATM_TOKEN }}to the step’senv.buildlabels the run in the app’s Environment × build report; the commit SHA works.
Each run becomes a completed Test Execution, tagged as an automation run, and every matched case’s latest result is updated. That’s what the app’s coverage, traceability and reports read. Posting the same externalRunId again doesn’t create a duplicate, so a retried step is safe. A row that finds no case is listed as unknownKey in the run’s diagnostics on the Automation tab rather than failing silently, and the endpoint itself answers with a plain status code, such as 401 for a bad token. The Import URL is a web trigger on Atlassian’s platform, and the app sends nothing to external servers.
Tips that save a rerun
- Run the reporting step after failed tests too. A step that only runs on green builds has nothing useful to say.
- Keep test names stable. Whatever you match on, a rename looks like one test vanishing and another appearing.
- Decide whether reporting may fail the build.
--fail-with-bodyhelps while you set it up; later, you may not want a Jira outage to block a merge. - Send the environment with every run, and the branch or commit where you can, so a failure on staging can be told apart from one on a feature branch.
- Keep tokens in secrets, never in the pipeline file. Atlassian API tokens expire after a year at most, so note the date and rotate before it, and again when the people who set them up move on.
Questions
Can Jira read a JUnit XML file on its own?
No. Jira has no model for test results, so a script, an automation flow or a test management app has to turn the report into something Jira stores: a comment, a work item or a test execution.
Should every failed test become a Bug?
Usually not. One broken build can fail dozens of tests for a single reason. Post one comment or work item per run, and raise Bugs once someone has looked at the failures.
What if my test runner doesn’t write JUnit XML?
Most can. pytest takes --junitxml=report.xml, Jest writes it through the jest-junit reporter, and Cucumber has a JUnit formatter next to its JSON one.
Which Jira account should the pipeline use?
One set up for automation, with permission to browse the space and to add comments or create work items there. Keep its API token in your CI tool’s secret store, never in the repository.
Keep reading
Try Advanced Test Management for Jira
Write, organize and run your tests in Jira, right next to the work items they verify. Link every test case to its requirement, record every run, and see what’s covered and what’s failing at a glance.