Use the CLI in a CI/CD Pipeline

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 backup a Coveo organization daily.

name: Backup
  schedule: 1
    - cron: 0 0 * * *
    name: Back up production Organization
    runs-on: ubuntu-latest
    environment: 'My Environment Name' 2
      - name: Authenticate to Git & checkout the repo 3
        uses: actions/checkout@v3
      - name: Authenticate to Coveo 4
        run: npx @coveo/cli auth:token -t $
      - 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 back ups. 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, connect to the target Coveo organization.
5 Fetch a fresh snapshot of the organization, commit, and push it to the target Git repo.