Bitbucket Pipelines
Scan pull request previews on Bitbucket Cloud with the QualityGate pipe, and post the result as a pull request comment.
QualityGate supports pull request and branch pipelines on Bitbucket Cloud. Bitbucket Data Center is not supported. The pipe image already contains the browser, so there is nothing to install.
1. Create the project
In the app, go to Projects → Create project → Bitbucket and enter:
- the repository as
workspace/repository, as it appears in its URL; - the repository UUID, shown under Repository settings, or printed by
echo $BITBUCKET_REPO_UUIDin any pipeline; - the default branch and the allowed preview domains.
QualityGate accepts runs only from the repository with that UUID, so a renamed or re-created repository cannot impersonate it.
Create an API key named Bitbucket Pipelines on the project card and copy it.
It is shown only once.
2. Add repository variables
Open Repository settings → Repository variables and add two Secured variables:
| Variable | Value |
|---|---|
QUALITYGATE_API_KEY | The project API key. |
QUALITYGATE_BITBUCKET_TOKEN | A repository access token with the pullrequest:write scope. Only needed for comments. |
3. Add the step
Download qualitygate.bitbucket-pipelines.yml from a
QualityGate release. It
contains the pipe image pinned by digest. Merge its step into your
bitbucket-pipelines.yml:
definitions:
steps:
- step: &qualitygate
name: QualityGate
oidc:
audiences:
- https://api.qualitygate.dev
script:
- pipe: docker://ghcr.io/qualitygatedev/bitbucket-pipe@sha256:<digest from the release>
variables:
QUALITYGATE_API_KEY: $QUALITYGATE_API_KEY
QUALITYGATE_URL: https://pr-${BITBUCKET_PR_ID}.preview.example.com
QUALITYGATE_ID_TOKEN: $BITBUCKET_STEP_OIDC_TOKEN
QUALITYGATE_BITBUCKET_TOKEN: $QUALITYGATE_BITBUCKET_TOKEN
QUALITYGATE_BUNDLE: a11y
QUALITYGATE_FAIL_ON: critical=0,serious=0
pipelines:
pull-requests:
'**':
- step: *qualitygate
branches:
main:
- step:
<<: *qualitygate
script:
- pipe: docker://ghcr.io/qualitygatedev/bitbucket-pipe@sha256:<digest from the release>
variables:
QUALITYGATE_API_KEY: $QUALITYGATE_API_KEY
QUALITYGATE_URL: https://www.example.com
QUALITYGATE_ID_TOKEN: $BITBUCKET_STEP_OIDC_TOKEN
QUALITYGATE_FAIL_ON: regression
The oidc block makes Bitbucket sign a short-lived identity token for the
step, which you pass on as QUALITYGATE_ID_TOKEN. QualityGate checks that it
was issued for your workspace and names the registered repository UUID.
The main branch step scans your production site and records the baseline
that regression mode compares pull requests
against. Pull requests are then compared page by page, whatever host their
preview uses.
Variables
Pipes only receive the variables you list under variables, so add every
option you use there.
| Variable | Required | Default | Purpose |
|---|---|---|---|
QUALITYGATE_API_KEY | Yes | none | Project API key. |
QUALITYGATE_URL | Yes | none | Preview URL on an allowed domain. |
QUALITYGATE_ID_TOKEN | Yes | none | Pass $BITBUCKET_STEP_OIDC_TOKEN. |
QUALITYGATE_BITBUCKET_TOKEN | For comments | none | Repository access token with pullrequest:write. |
QUALITYGATE_BUNDLE | No | a11y | See Bundles and checks. |
QUALITYGATE_FAIL_ON | No | critical=0,serious=0 | Limits or regression. |
QUALITYGATE_PREVIEW_USERNAME | No | none | Basic auth username for a password-protected preview. |
QUALITYGATE_PREVIEW_PASSWORD | No | none | Basic auth password. Use a Secured variable. |
QUALITYGATE_PREVIEW_HEADERS | No | none | Extra headers for the preview, one Name: value per line. |
QUALITYGATE_WAIT_FOR_URL | No | true | Wait for the preview to answer before scanning. |
QUALITYGATE_WAIT_TIMEOUT | No | 120 | Seconds to wait for the preview. |
QUALITYGATE_COMMENT | No | true | Post or update the pull request comment. Set 'false' to skip it and the token. |
QUALITYGATE_URLS | No | none | Several pages to scan, one per line or comma separated. See Several pages. |
QUALITYGATE_GATE_SCOPE | No | combined | With QUALITYGATE_URLS: combined applies the limits to all pages together, page to each page. |
QUALITYGATE_COUNT_MODE | No | occurrences | Set groups to count distinct check, rule and selector groups. |
QUALITYGATE_IGNORE | No | none | Runtime URL or message patterns, or scoped or unscoped rule: entries. See Ignoring known environment differences. |
QUALITYGATE_CONCURRENCY | No | 2 | Maximum pages scanned in parallel, from 1 to 8. |
QUALITYGATE_TIME_BUDGET_SECONDS | No | 900 | Warn at 80% of this duration and identify the slowest page and check. |
QUALITYGATE_BUDGETS | No | none | Limits for the perf bundle, such as lcp=2500,cls=0.1,tbt=200. See Budgets. |
QUALITYGATE_PERF_FORM_FACTOR | No | mobile | mobile, desktop, or both for the perf bundle. |
QUALITYGATE_FAIL_ON_NEW | No | false | Set 'true' to count QUALITYGATE_FAIL_ON limits against new issues only. |
QUALITYGATE_BASELINE_BRANCH | No | default branch | Branch to compare with in regression mode. See Comparing with another branch. |
QUALITYGATE_SITE_KEY | No | none | Stable site name for separate regression baselines. |
QUALITYGATE_REPORT_FILE | No | false | Set 'true' to save every finding to qualitygate-report.json. See Report file. |
To fail only on issues a pull request introduces, set
QUALITYGATE_FAIL_ON: regression; see
Gates and regression mode.
Several pages in one step
QUALITYGATE_URLS scans several pages of the same preview in one step and
posts one comment. Paths are resolved against QUALITYGATE_URL; full URLs are
accepted too. List every page you want, including / for the home page:
variables:
QUALITYGATE_URL: https://pr-${BITBUCKET_PR_ID}.preview.example.com/
QUALITYGATE_URLS: |
/
/women/dresses
/product/linen-dress
/checkout/cart
- Each page is its own run: it is authorized, counted against your allowance, and recorded in history separately. At most 20 pages.
- By default the limits in
QUALITYGATE_FAIL_ONapply to all pages together: withcritical=0,serious=1, two pages with one serious finding each fail the step. QualityGate computes this combined verdict on its servers from the stored findings, as it does for every verdict. In regression mode the new findings of each page, against that page’s baseline, are added up. QUALITYGATE_GATE_SCOPE: pageapplies the limits to each page alone instead, and the step fails when any page fails.- Either way every page also gets its own verdict, shown in the table and in run history. A combined verdict is never looser than the pages’ own: a page that fails alone always fails the step.
- The comment starts with one table of every page and its counts, followed by one section per page.
- Up to two pages scan at once by default. Each page gets its own browser
context. Lighthouse keeps its isolated browser and scans pages serially.
Set
QUALITYGATE_CONCURRENCY: '1'to scan in series. A page that cannot be scanned fails the step. - With
QUALITYGATE_COUNT_MODE: groups, repeated findings with the same check, rule and normalized selector count once in the gate’s scope. The default keeps the previous gate counts, including existing runtime URL aggregation. - The comment explains when a PR’s bundle, URL list or ignore list changes. Shared pages remain comparable when only the URL list changes. Scan details include page duration, and the summary shows the total duration.
Without QUALITYGATE_URLS, the pipe scans QUALITYGATE_URL exactly as before.
Comments
The comment shows the verdict, occurrence and group totals, and the three most
important groups. Repeated findings show a count and representative selectors.
Scan details include the requested URL,
the final URL after redirects with each status code, and the security headers
the page sends. A store that redirects / to /de-de-eur/ therefore shows
which locale was scanned.
Bitbucket does not render HTML in comments, so these sections are headings rather than collapsible blocks. The pipe updates its own comment on later runs. A comment lists up to 50 groups for one page, or shares about 100 groups across several pages. If the rendered comment exceeds 24,000 UTF-8 bytes, it keeps the per-page counts and links to the pipeline. Ignored findings and the patterns that matched appear under Ignored. Scan details list unused patterns.
Report file
Set QUALITYGATE_REPORT_FILE: 'true' to save every finding of every page to
qualitygate-report.json in the clone directory, and keep it as an artifact:
- step:
<<: *qualitygate
artifacts:
- qualitygate-report.json
The comment names the file. It contains scrubbed findings with full selectors, group totals, ignored findings and timings. If the file cannot be written, the step logs a warning and carries on.
Secured variables in the log
Bitbucket hides the value of a secured variable everywhere it appears in the
step log, not only where the variable is printed. If your basic auth username
also occurs in the preview host, for example a username acme on
test.acme-m.com, every URL in the log reads
https://test.$QUALITYGATE_PREVIEW_USERNAME-m.com/. The scan is not affected.
The pipe never prints the value of QUALITYGATE_PREVIEW_USERNAME,
QUALITYGATE_PREVIEW_PASSWORD, or QUALITYGATE_API_KEY. When one of them
occurs in a scanned URL, it prints a note saying so. The pull request comment
and the report file are not masked and show the real URL. To keep the log
readable, choose a username that does not occur in your host name.
Repository security preview
The dependency pilot is available to selected projects. Enable it under Repository security on the project. Use the project API key and an OIDC token for the QualityGate audience. Pin the pipe to a release that includes standalone repository scanning.
This step uses the Magento checkout’s Composer inventory:
- step:
name: QualityGate dependencies
oidc:
audiences:
- https://api.qualitygate.dev
script:
- pipe: docker://ghcr.io/qualitygatedev/bitbucket-pipe@sha256:<release-digest>
variables:
QUALITYGATE_API_KEY: $QUALITYGATE_API_KEY
QUALITYGATE_ID_TOKEN: $BITBUCKET_STEP_OIDC_TOKEN
QUALITYGATE_REPOSITORY_SECURITY: 'true'
QUALITYGATE_REPOSITORY_SECURITY_COMPOSER_LOCK: composer.lock
For Scala, generate a CycloneDX JSON SBOM from the resolved sbt runtime
classpath. Make the file available under the checkout before invoking the pipe.
Use QUALITYGATE_REPOSITORY_SECURITY_SBOM: target/runtime.bom.json in place
of the Composer variable and set it to the actual artifact path.
Leave the preview URL out for a standalone scan. The pipe verifies inventory coverage. QualityGate matches exact package versions against OSV in the background. The project’s Repository security page shows the results and refresh status. Keep your existing merge gate during the pilot.