Adding Knock to your CI/CD pipeline

Learn how to add Knock to your deployment pipeline with our command line interface.

With the Knock CLI, you can add Knock directly into your existing CI/CD pipeline in order to automate the promotion of changes to Workflows, Layouts, and Translations between environments during testing and deployment.

This guide assumes that you have created a “Staging” environment in Knock in addition to the Development and Production environments that are provided by default. It also assumes that you have installed the Knock CLI on your local machine.

Local development

With the Knock CLI, you can pull resources from the Knock dashboard and develop them locally using the knock workflow pull --all, knock layout pull --all, and knock translation pull --all commands. You can also work with specific resources by providing a key rather than using the --all flag.

Once you’re ready to send your updates back to Knock’s Development environment, you can push (knock workflow push --all) and commit (knock commit) changes directly from the command line in the same way that you would save and commit them in your dashboard. You can also perform both of these actions at once by using the --commit flag on any push command.

🛑
Note: As with working directly in your dashboard, any uncommitted changes that are made to a Knock resource and pushed to Knock can be overwritten by another user who is working on the same resource. It’s important to commit any changes that you want to persist while working in the Development environment.

Pushing to your remote repository and deploying to staging

When you’re ready to commit your locally-developed feature (including any updates to your Knock resources) to a remote git repository and kick off a test build in your staging environment, you can use the Knock CLI to automate the promotion of changes to your Knock resources across Knock environments. An example implementation might be done with a GitHub Action that promotes all of your committed updates from the Knock Development environment to your Staging environment, so that your application’s staging deployment will have access to all of your notifications changes.

👀
When using the knock commit promote command with the --to flag, the CLI will automatically locate any promotion-eligible changes that exist in the environment one "level" lower in your list of Knock environments in order to promote them to the designated environment. To view the current order of all your configured environments, navigate to Settings > Environments in your Knock dashboard.

This sample GitHub Action .yaml file shows how you might promote all committed changes from your Development environment to your Staging environment:


Deploying to production

Once a pull request has been approved and is ready to be merged into your main branch, you can once again include the Knock CLI in your CI/CD pipeline to promote your relevant Knock resources to your Production environment.

This sample GitHub Action .yaml file shows how you might promote all changes from your Staging environment to your Production environment: