Usage in a CI/CD pipeline

This is for:

Developer

Automating backups and deployments is very common in software development. It allows developers and administrators to make changes faster and also to revert said changes easily. The Coveo CLI lets you carry out such operations using a source control management system and a Continuous Integration/Continuous Delivery (CI/CD) system. The following code sample exemplifies how to create a GitHub Action workflow to back up a Coveo organization daily.

name: Backup
on:
  workflow_dispatch:
  schedule: 1
    - cron: 0 0 * * *
jobs:
  backup:
    name: Back up production Organization
    runs-on: ubuntu-latest
    environment: 'My Environment Name' 2
    steps:
      - name: Authenticate to Git & checkout the repo 3
        uses: actions/checkout@v3
      - name: Authenticate to Coveo 4
        run: echo ${{secrets.MY_API_KEY}} | npx @coveo/cli auth:token --stdin
      - name: Backup organization 5
        run: |
          npx @coveo/cli org:resources:pull -f
          git add .
          git commit -m "backup my coveo organization"
          git push
1 Choose how and when to create backups. Here you use a CRON job that runs every day at midnight UTC.
2 To manage your deployments, here you use a GitHub Actions Environment that contains a secret API key with the privileges required to manage snapshots. The API Key requires at the very least EDIT and VIEW access to snapshots. It also requires VIEW access to the resources you want to back up.
3 The checkout action connects to the Git repository and will let you push later.
4 Using the secret API key defined in the GitHub Action environment (MY_API_KEY), connect to the target Coveo organization. The API key is passed to the Coveo CLI via stdin.
5 Fetch a fresh snapshot of the organization, commit, and push it to the target Git repository.