Usage in a CI/CD pipeline
Usage in a CI/CD pipeline
This is for:
DeveloperAutomating 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:
- cron: 0 0 * * *
jobs:
backup:
name: Back up production Organization
runs-on: ubuntu-latest
environment: 'My Environment Name'
steps:
- name: Authenticate to Git & checkout the repo
uses: actions/checkout@v3
- name: Authenticate to Coveo
run: echo ${{secrets.MY_API_KEY}} | npx @coveo/cli auth:token --stdin
- name: Backup organization
run: |
npx @coveo/cli org:resources:pull -f
git add .
git commit -m "backup my coveo organization"
git push
Choose how and when to create backups. Here you use a CRON job that runs every day at midnight UTC. | |
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. |
|
The checkout action connects to the Git repository and will let you push later. | |
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. |
|
Fetch a fresh snapshot of the organization, commit, and push it to the target Git repository. |