Use hart in CI
Sign in with an API key, Sync and run stages from a pipeline, and read the exit codes.
A pipeline can drive a workspace the way you do: pull the new commit, Sync, prepare, test and run. hart reads its
settings from environment variables, never asks a question it cannot answer, and exits with a code your pipeline can
branch on.
Create an API key for the pipeline
- In the console, open Account settings → API keys and click Add API key.
- Name it after the pipeline, for example
CI shop, and pick an expiry. - Copy the key; it is shown once. Store it as a secret of your CI system, for example
HART_TOKEN.
The key acts as you, with your roles. Running stages and Sync needs the Editor role on the workspace.
Tell hart where to go
Set these variables in the pipeline; nothing else is needed, no hart login:
| Variable | Value |
|---|---|
HART_API | your console's address, e.g. https://console.example.com |
HART_TOKEN | the API key, from the CI system's secrets |
HART_TEAM | the team's id |
HART_WORKSPACE | the workspace's id |
hart whoami checks them. The ids are in the console's addresses and in hart ws list -o json.
A pipeline script
set -euo pipefail
hart whoami
hart ws wake --wait
hart git pull
hart sync --yes --wait
hart prepare -f
hart test -f
hart runhart ws wake --waitwakes the workspace if it sleeps: Sync andgit pullwork on the workspace's IDE, which readsharthelm.yml.hart git pullfast-forwards/data/appto the branch's new commit.hart sync --yes --waitapplies the plan without asking and waits until the services have rolled out. With--yesa secret without a value fails the Sync instead of prompting; set secrets beforehand withhart secret set.hart prepare -fandhart test -ffollow the output and fail when the stage fails.hart runstarts the services.
Use hart sync --dry-run in a pull-request job to print the plan without changing anything.
An example workflow
The same steps in a GitHub Actions-style workflow. Get hart from wherever your installation keeps its release
archives; the address below is a placeholder.
name: deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
env:
HART_API: https://console.example.com
HART_TOKEN: ${{ secrets.HART_TOKEN }}
HART_TEAM: "7"
HART_WORKSPACE: "42"
steps:
- name: Install hart
run: |
curl -fsSL -o hart.tar.gz "https://downloads.example.com/hart_1.0.2_linux_amd64.tar.gz"
tar -xzf hart.tar.gz hart
sudo install -m 0755 hart /usr/local/bin/hart
- name: Deploy
run: |
hart ws wake --wait
hart git pull
hart sync --yes --wait
hart prepare -f
hart test -f
hart runCheck the archive against the release's SHA256SUMS file as in Install hart.
Exit codes
| Code | Meaning | Typical cause in CI |
|---|---|---|
| 0 | success | |
| 1 | anything else | a failed stage with -f, a network error, problems found by hart validate |
| 2 | usage | a missing setting: no API, team or workspace |
| 3 | not signed in (401) | the key expired, was deleted or regenerated |
| 4 | forbidden (403) | the key's user lacks the role |
| 5 | not found (404) | a wrong team or workspace id |
| 6 | conflict (409, 412, 428) | a blocked Sync (quota, a missing image), a stage that already runs |
The full list is under Exit codes. Messages go to stderr; -o json puts results on
stdout for jq.
Wake and quota
hart ws wake reports why something cannot wake: the team's quota or the cluster has no room, or its nodes are
switched off for the night. Retry later or make room. See Sleep and wake.