Skip to content

Recipes

Complete examples for common tasks. Each one works on a terminal and in a script; in scripts, add -o json and read the result with jq.

Deploy from a CI pipeline

Give the pipeline a write token for a dedicated user (see Logging in) and let the job decide the pipeline's result:

GitLab CI:

deploy_qa:
  stage: deploy
  image: debian:stable-slim
  script:
    - apt-get update -qq && apt-get install -y -qq curl ca-certificates >/dev/null
    - curl -fsSL "https://clarive.com/downloads/cli/clarive-cli_${CLARIVE_CLI_VERSION}_linux-x86_64.tar.gz" | tar xz -C /usr/local/bin clarive
    - clarive job create QA "$CHANGESET_MID" --wait --logs
  variables:
    CLARIVE_URL: https://clarive.example.com
    CLARIVE_CLI_VERSION: latest     # or a release version, to pin the CLI
    # CLARIVE_TOKEN comes from a masked CI/CD variable

GitHub Actions:

- name: Deploy to QA
  env:
    CLARIVE_URL: https://clarive.example.com
    CLARIVE_TOKEN: ${{ secrets.CLARIVE_TOKEN }}
  run: clarive job create QA "${{ vars.CHANGESET_MID }}" --wait --logs

Jenkins (shell step, with the token bound from a credential):

withCredentials([string(credentialsId: 'clarive-token', variable: 'CLARIVE_TOKEN')]) {
  sh 'CLARIVE_URL=https://clarive.example.com clarive job create QA 101 --wait --logs'
}

--wait exits 0 when the job finished OK and 9 otherwise, so the step fails when the deployment fails. The GitLab job downloads the CLI from clarive.com, where every release publishes it (see Install); set CLARIVE_CLI_VERSION to a release version instead of latest to pin it.

Start the day

clarive topic search --assigned-to-me --only-open --sort modified_on
clarive job list --status ERROR --period 1D
clarive job list --status APPROVAL                 # jobs waiting for someone to approve
clarive system active-messages

Find out why a job failed

clarive job get JOB-00012                          # status, step, environment, changesets
clarive job get-root-cause JOB-00012               # the root cause analysis of its log
clarive job logs JOB-00012 --levels error
clarive job get-summary JOB-00012                  # every service's result by step
clarive job runner-log JOB-00012 -O -              # the raw output of the process that ran it

Then rerun it from a step, or answer it if it is waiting in a trap:

clarive job restart JOB-00012 --step RUN
clarive job trap-action JOB-00012 retry            # or skip, pause, error

Move a topic, and understand a refusal

clarive topic list-next-statuses 4321               # where it may go
clarive topic change-status 4321 "In Review"
clarive topic explain-status-change 4321 Done       # why not

explain-status-change answers with the reasons: no transition in the workflow, the roles that allow it and the roles you hold, a required field, or a status that is reached only by deploying. It changes nothing.

Search and report on topics

clarive topic search "login page" --categories Bug --only-open
clarive topic search --created-by jdoe --statuses "In Progress"
clarive topic search --assigned-to jdoe,asmith --projects Web
clarive topic export --categories Bug --only-open --format csv -O bugs.csv
clarive topic add-comment 4321 "Deployed to QA in JOB-00012"

Keep rules under version control

clarive rule list deploy
clarive rule get "Deploy web" --hcl > rules/deploy-web.hcl     # commit it to git
clarive rule edit "Deploy web"                                 # edit, check, save
clarive rule list-versions "Deploy web"
clarive rule diff-versions "Deploy web" 12 14              # as HCL, unified diff
clarive rule restore-version "Deploy web" 12                   # saved as a new version

Run a command and ship a file

clarive server check-connection web01
clarive server execute web01 "systemctl status app"
clarive file put web01 /opt/app/app.conf --file ./app.conf --mkdir
clarive file get web01 /var/log/app/error.log -O ./error.log

The server must be a resource (CI) with an agent (ssh, clax or a worker).

Look at the Clarive server's own logs (administrators)

clarive system list-logs
clarive system read-log cla-web-myhost-8080-prod.log --query error --lines 50
clarive system read-log cla-disp-myhost-prod.log --query 'timeout|refused' --regex

Follow a log the way tail -f does by passing back next_offset and file_id:

r=$(clarive system read-log cla-web-myhost-8080-prod.log --lines 1 -o json)
while sleep 5; do
  r=$(clarive system read-log cla-web-myhost-8080-prod.log -o json \
        --offset "$(jq -r .next_offset <<<"$r")" --file-id "$(jq -r .file_id <<<"$r")")
  jq -r '.lines[]' <<<"$r"
done

Work with resources

clarive ci list-classes
clarive ci search generic_server web --columns mid,name,hostname
clarive ci get generic_server-12
clarive ci get-many generic_server-12 topic-4321 job-998     # several, of any classes
clarive ci relations generic_server-12
clarive ci export generic_server --mids generic_server-12,generic_server-13 --format yaml -O servers.yaml

Secrets (passwords, keys, tokens) are always masked in what the API returns; sending the masked value back in an update keeps the stored one.

Manage tokens of a pipeline user (user administrators)

clarive auth list-tokens --username ci-deployer
clarive auth revoke-token clapat_0a1b --username ci-deployer