Sign inSign up
Introduction

Automate with continuous integration

Configure CI to publish your Storybook and run Chromatic’s automation whenever you push code. Badge your PRs to get notified about test and review results.

Continuous integration

Configure CI

Before we begin, make sure you set the CHROMATIC_PROJECT_TOKEN environment variable (sometimes referred to as “secrets”) in your CI service’s configuration. Add a chromatic script to your package.json if you don’t have one already, and make sure chromatic is listed in devDependencies.

"scripts": {
  "chromatic": "chromatic --exit-zero-on-changes"
}

Integrate with popular CI tools like you would any other job. Run npm run chromatic to publish your Storybook. If UI Test or UI Review are enabled, it will return a non-zero exit code when there are changes. For example:

- run:
    command: npm install # install dependencies
- run:
    command: npm test # run your unit tests
- run:
    command: npm run chromatic # publish Storybook and run visual tests

Here’s how we recommend configuring Chromatic for popular CI services:

Pull request checks

When a build runs it will automatically add a PR status check to the current pull request indicating the state of the build. By default, you’ll see Storybook Publish. If you enabled UI Tests or UI Review you’ll also see their respective checks.

GitHub, Bitbucket, or GitLab projects that are linked to a repository get this feature out of the box. If you use other version control services to host your code, you can write a custom CI script to add a check for Chromatic (via your CI provider).

Require checks in GitHub, GitLab, or Bitbucket to ensure they are completed before merging.

PR badges


You’re all set up

Now that you’ve set up Chromatic, learn the recommended workflow in development and during the pull request.

Learn workflow


Troubleshooting

Can I hide the CI messages in the web app?

Chromatic detects CI test runs for most services. But it’s not possible for every system, which results in users seeing persistent “Setup CI / Automation” messages in the UI.

If this is happening to you, prepend CI=true to your test command like so CI=true yarn chromatic... to hide the “Setup CI” messages in Chromatic. Learn more.

Why aren't pull request checks syncing with my git provider?

Pull/merge request checks show the status of your UI Tests and UI Review in GitHub, Bitbucket, or GitLab. If you find that your status checks are out of sync between Chromatic and your git provider, try the solutions below.

1. Check that your project is linked to a git provider

Go to your Project » Manage » Configure tab under the “Connected Applications”. Then confirm that there is a repository connected to your project and that the access token is valid.

2. Check whether commits are successfully linked to builds

Chromatic runs builds for each commit to power UI Tests and UI Review. We expect the build commit in Chromatic to match the commit in your repository. But some CI environments and git providers create an “ephemeral” merge commit if your feature branch is not up to date with your default base branch (master, main, develop, etc).

You can verify that you’re in this situation by going to the Build page and noting the commit hash. If your project is “linked” to a git provider, you can also click on the commit to go straight to the git provider website. If you get a “Not Found” page indicating the commit doesn’t exist then this issue applies to you.

The way to fix this is to set the Chromatic environment variables: CHROMATIC_SHA, CHROMATIC_BRANCH, CHROMATIC_SLUG. Note, you must set all three.

3. Check if your environment variables are set correctly

Another possibility is that your environment variables CHROMATIC_SHA, CHROMATIC_BRANCH, CHROMATIC_SLUG are not configured correctly.

The most likely reason is that you are pulling the incorrect value from your CI provider to set the variables or you are working on a forked repository and have not configured the variables to match the base repository.

If none of these situations apply to you, email support and attach the full job that includes chromatic for your particular CI environment.