Use with Jenkins
Status: Stable
Instructions for a consumer that runs the design-tests CLI in a Jenkins pipeline. Two pipelines are the reference, and every number below comes from them:
- CMS site: its own design-tests repository,
.build/pipeline/design-tests/Jenkinsfileon the branchnext. The nightly jobdesign-testsand the validation jobdesign-tests-nextrun it. - Storybook consumer: its own design-tests repository,
.build/pipeline/design-tests/Jenkinsfile.
For the report page and its JavaScript, read Jenkins Resource Root URL. For the commands and flags, read the CLI Reference. For the review of the new baselines, read Baseline Management.
Stages
Both pipelines run on a Kubernetes agent and have the same two stages.
- Design Tests. Install, run, archive, count.
- Update Design Tests. Runs only when the run found new or changed images. Promotes the new images and pushes a branch.
The Storybook consumer has two more stages before them (Checkout, Materialise baselines) because its baselines live in Git LFS. A consumer without LFS does not need them.
Run
- Install the dependencies:
pnpm install --frozen-lockfile --ignore-scripts. Both pipelines write an.npmrcfrom a Jenkins file credential first (withCredentials([file(...)])), because@qs/design-testscomes from the Quatico Artifactory registry. - Run
design-tests run --all. The CMS site calls it throughpnpm run test.
The exit code of run depends on the mode (determineExitCode, src/cli/executor.ts):
| Mode | Exit code |
|---|---|
| Report-only (default) | 0 once the report is written, also when images differ; 2 when the run captured nothing |
--fail-on-changes | 0 when all items pass; 1 when only visual differences exist; 2 on capture failures or an empty run |
The pipelines use the default mode. A build therefore does not fail because of a visual difference. The pipeline reads manifest.json and sets the result itself: the CMS site sets UNSTABLE when summary.errors is above 0.
Counts
Read the counts from the summary object in <reportDir>/manifest.json. The CMS site reads them with node -e and so does not depend on the Pipeline Utility Steps plugin:
def counts = sh(
returnStdout: true,
script: '''
node -e '
const s = JSON.parse(require("fs").readFileSync("tests/__report__/manifest.json", "utf-8")).summary;
process.stdout.write([s.passed, s.failed, s.new, s.deleted, s.errors].map((n) => n || 0).join(" "));
'
'''
).trim().split(' ')
The Storybook consumer reads reg.json with readJSON, which needs the Pipeline Utility Steps plugin. manifest.json is also the file that baseline-update promotes from, so the gate and the promotion read the same lists.
Archive
Archive these paths with archiveArtifacts:
- The report directory, for example
tests/__report__/**/*. - The diff directory, for example
tests/__diff_output__/**/*. - The baseline image and the actual image of each item that did not pass. Take the
imagePathof every item in thefailed,newanderrorslists ofmanifest.json, and join the paths with commas into oneartifactspattern. The report links the images by relative path, so they must keep their place in the workspace. - With
DESIGN_TESTS_DIAGNOSTICS=true: the.diag.jsonsidecar of each non-passing capture (the sameimagePathwith.diag.jsonas the extension, in the actual directory). See Diagnostics sidecar.
Do not archive the images of passed items. A full run produces thousands of them, and they fill the controller volume (see "Artifact footprint" in the Stabilization Playbook).
The report lists the passed items and loads their images from the archive. An image that fails to load shows a placeholder: "Passed: the capture matched the baseline. The image is not in this report." for a passed item, and "Image not in this report." for any other image. The placeholder is an inline script and style in index.html. It needs no network access and no setting. The report needs inline scripts, so it works on a Jenkins resource root URL host or under a relaxed Content-Security-Policy (see Jenkins Resource Root URL).
Baseline link
With the option report.baselineLink, the placeholder of a passed item also shows the link "Open the baseline image". The link opens the baseline file in the repository host, at the suite commit that the run compared against. The reader needs read access to the suite repository; the link opens in the reader's browser with the reader's own login, so it needs no change to the Content-Security-Policy.
The option is a URL template with two placeholders: {commit} is the suite commit, and {path} is the image path relative to the repository root. The library holds no host; the consumer names it in the template:
// .designTests.js
module.exports = {
report: {
// Bitbucket Cloud
baselineLink: "https://bitbucket.org/<workspace>/<repository>/src/{commit}/{path}",
// GitHub: "https://github.com/<owner>/<repository>/blob/{commit}/{path}"
},
};
The configuration check rejects a template that is not an http or https URL, or that lacks {commit} or {path}.
The run reads the commit with git rev-parse HEAD in the baseline directory and records it in manifest.json as baselineSource (see Run record). It needs no pipeline variable. The report has no link when baselineSource is missing (the baseline directory is not in a git checkout) or has dirty: true (the baseline directory has uncommitted changes, so the commit does not describe the baseline). The placeholder text stays in both cases. A report with the option unset has no link.
Baseline update
When failed plus new is above 0, the second stage runs design-tests baseline-update and pushes the result:
baseline-updatecopies thenewandfailedimages from the actual directory into the baseline directory and writesRUN.json, andBASELINE.jsonwhen it copied or removed at least one image; otherwiseBASELINE.jsonstays as it is. It skipserrorsitems.- Inside
withCredentials([gitUsernamePassword(credentialsId: '...')]), the pipeline sets the Git user, creates the branchbaseline-update/<build number>, runsgit add -Aon the baseline directory, commits and pushes. The CMS site names the branch of the validation jobbaseline-update/<job name>-<build number>. - A person opens the pull request and reviews the images.
Post to Slack only from the nightly job. The CMS site checks env.JOB_BASE_NAME == 'design-tests', so the validation job design-tests-next stays quiet. The message links the report and the pull-request page of the branch.
Run record
design-tests run records where a run came from in manifest.json:
ciholdsbuildNumber,buildUrlandjobName, read from the Jenkins variablesBUILD_NUMBER,BUILD_URLandJOB_NAME. A variable that is not set leaves its field out, and outside CI the field is absent. Other CI systems are not read.baselineSourceholdscommit,pathanddirty:git rev-parse HEADof the repository that holds the baseline directory, the path of the baseline directory inside it, and whether the baseline directory has uncommitted changes. Outside a git checkout the field is absent.
ci.buildUrl is the plain BUILD_URL of the build. The config function jenkins.buildUrl(env) still builds the link to the report artifacts.
baseline-update writes RUN.json into the baseline directory, next to BASELINE.json, on every update. RUN.json names the run the last update read; when that update changed no image, BASELINE.json still describes the run the images came from. It is a plain git file: the LFS rule of a suite that tracks *.png does not match it. The git add of the baseline directory in the second stage adds it, so a baseline-update/<n> branch carries the run record with no pipeline change. RUN.json holds:
schemaVersion, which starts at 1.ci,baselineSource,current,baselineandsummary, copied frommanifest.json.- The items that did not pass:
failed,new,errorsanddeleted. Afaileditem thatretries.onDifftook again carriesattemptsDiffer;RUN.jsonleaves outattemptPath, because the kept attempt lives in the report (see Retries). flaky: the passed items that needed at least one retry.summary.flakyholds their count.
RUN.json holds no passed items. A suite with thousands of captures would grow its repository by every run, and the review reads the passed items from the baseline directory and the counts from summary.
baseline-update also copies ci into the field build of BASELINE.json when ci has a build number. reference stays the app version the baseline was captured from; build names the Jenkins build that captured it.
Retention. Keep at least the previous baseline-update/<n> branch. A review finds the previous run of a job as the newest older branch whose RUN.json names the same jobName.
Pruning
baseline-update --prune removes the baseline images of stories that the run no longer captures (the deleted items). Use it only after a run --all.
The CMS site runs baseline-update without --prune until it removes its old orphans in a change of its own: 450 files of renamed or deleted stories. Without --prune:
- Do not count
deleteditems as an update. The CMS site setsHAS_SCREENSHOT_UPDATESfromfailedplusnewonly, becausebaseline-updatechanges no file for a deleted item. - Do not archive the images of
deleteditems. On the CMS site they take 109 MB.
Report link
The report link must appear in the build list. Two routes work.
Badge plugin. The step addInfoBadge(text: 'Design Test Report', link: reportUrl) adds an (i) icon with the link to each build row. The Storybook consumer uses it. Plugin page: https://plugins.jenkins.io/badge/.
HTML description. currentBuild.description = "<a href=\"${env.REPORT_URL}\">Design Test Report</a>" shows a link only when Jenkins formats the description as HTML. That needs the OWASP Markup Formatter plugin (antisamy-markup-formatter, https://plugins.jenkins.io/antisamy-markup-formatter/) and the global markup formatter set to Safe HTML. With markupFormatter: "plainText", Jenkins shows the HTML escaped. This is the JCasC setting of the Quatico Jenkins instances of the CMS site, apps and the Storybook consumer in November 2026, and the CMS site design-tests-next #31 showed the escaped tag. Jenkins documentation: https://www.jenkins.io/doc/book/security/markup-formatter/.
On an instance with plainText, use the badge, or set the formatter to Safe HTML. The CMS site instance had no Badge plugin in November 2026: the plugin is in the shared plugin list since 2026-09-18, and the shared Jenkins image that the CMS site runs was built before that.
Resources
The CMS site runs 16 workers (DESIGN_TESTS__PLAYWRIGHT__WORKERS = '16') on runner nodes with 16 vCPUs. The Playwright container requests 8 CPUs (resources.requests.cpu: "8").
Evidence: without the request, design-tests-next #24 had elementHandle.screenshot: Timeout 10000ms exceeded in 15 unrelated stories, while two other design-test jobs started on the same nodes. Builds #25 to #32 with the request had none (#30 ended early, see "Node shutdown"). A full run of the CMS site of 1,374 captures took 21 to 28 minutes for the captures and 25 to 35 minutes for the whole build.
Node shutdown
A node shutdown can terminate the pod. The CMS site design-tests-next #30 ended with "Pod was terminated in response to imminent node shutdown". Run the job again.
Plugins
List of the plugins that the two Jenkinsfiles use:
- Kubernetes: the
agent { kubernetes { ... } }block (both). - Git:
gitUsernamePassword(both). - Credentials Binding:
withCredentialswithfile(...)andgitUsernamePassword(...)(both). - AnsiColor (optional):
ansiColor('xterm-256color')(both). - Slack Notification (optional):
slackSend(both). - Badge:
addInfoBadge(the Storybook consumer), or OWASP Markup Formatter for an HTML description (the CMS site, see "Report link"). - Pipeline Utility Steps:
readJSON(the Storybook consumer only). Not needed when the pipeline readsmanifest.jsonwithnode -e.