Use Shopify CLI in a CI/CD pipeline
If you have a theme that you want to work with programmatically, then you can integrate Shopify CLI into your CI/CD pipeline to perform actions like pushing, pulling, and publishing a theme.
What you'll learn
Anchor link to section titled "What you'll learn"In this tutorial, you'll learn how to set up your CI/CD pipeline to work with themes programmatically. To do so, you'll gather the credentials necessary to run the CLI commands, and then add a step to your CI/CD pipeline that installs Shopify CLI and runs CLI commands.
Requirements
Anchor link to section titled "Requirements"Step 1: Get a Theme Access password for the store
Anchor link to section titled "Step 1: Get a Theme Access password for the store"For each store that you want to interact with programmatically using Shopify CLI, you need to get a Theme Access password. These are generated using the Theme Access app.
To learn about the requirements for installing and using the Theme Access app, and instructions on how to generate a new password, refer to Manage theme access.
Step 2: Integrate Shopify CLI into your pipeline
Anchor link to section titled "Step 2: Integrate Shopify CLI into your pipeline"After you get a Theme Access password for the store, you can integrate Shopify CLI into your continuous deployment pipeline using your CI/CD provider.
The CD pipeline step should install Shopify CLI and all of its dependencies.
To run Shopify CLI theme commands programmatically using your CD pipeline step, include the following:
Environment variables:
Name Required? Value SHOPIFY_CLI_THEME_TOKEN
Yes The Theme Access password that you generated or were given by a merchant SHOPIFY_FLAG_STORE
Yes The store that you want to interact with SHOPIFY_FLAG_FORCE
No Pass this variable with a value of 1
to turn off interactive prompts. You may want to use this variable if your Shopify CLI pipeline step is timing out.Where possible, you should protect the Theme Access password by masking it or storing it as a secret.
A step that sets up Ruby and bundler.
A step that sets up Node.js.
A step that installs Shopify CLI globally.
A step that runs the CLI command that you want to execute.
Example (GitHub Actions)
Anchor link to section titled "Example (GitHub Actions)"Below is an example of a step that you might add to your GitHub Actions workflow. It pushes a theme to a Shopify store when code is pushed to the main
branch.