Publish an HTML report from Bitbucket Pipelines
Bitbucket Pipelines is happy to build the report and then gives it nowhere
to live. artifacts: keeps the files for 14 days and serves them as a
download. The Test Reports tab renders results, but only from
JUnit-format XML — a coverage page, a Lighthouse run, a benchmark
dashboard or an eval scoreboard has no tab to appear in. And Bitbucket
Cloud has no Pages-style static hosting to deploy to, so the usual fallback
isn't there either.
What teams do instead: download the zip, or screenshot it into the PR.
One step, one URL
Store a scoped token (reports:write is enough) as a
secured repository variable, create the Comma report once, and keep its
id in a plain repository variable:
pipelines:
default:
- step:
name: Test and publish report
image: node:22
script:
- npm ci && npm run coverage
- >-
curl -fsS -X PATCH
"https://commareports.com/api/v1/reports/$COMMA_REPORT_ID"
-H "Authorization: Bearer $COMMA_API_TOKEN"
-H "Content-Type: application/json"
-d "$(jq -n --rawfile html coverage/index.html
--arg title "Coverage — ${BITBUCKET_COMMIT:0:7}"
'{title: $title, html: $html}')"
after-script:
- echo "Report: https://commareports.com/p/$COMMA_REPORT_ID"
Two details earn their keep:
PATCH, notPOST. Each run appends a revision at the same URL — one bookmark per report, and any two runs can be diffed.- Publish on red too. Put the call in
after-script(which runs even when the step fails) if the report is the thing you most want when the build breaks.after-scriptalso hasBITBUCKET_EXIT_CODEavailable, so the revision title can carry the outcome.
jq isn't in every image — apt-get install -y jq or pick an image that
has it. In a minimal image, generating the JSON body with python3 -c is
the shorter path.