Scripting & CI
The CLI was designed for automation as much as for people: credentials from the environment, one JSON document per run, stable exit codes, safe retries and no surprise prompts. These recipes show common patterns.
Principles
- Authenticate with the environment.
VELA_URLandVELA_KEYwork without any config file. - Use a narrow key.
velad key create --name ci --scope rw --prefix ci/. A leaked CI key then touches onlyci/and cannot purge. - Parse
--json, branch on exit codes. Human output may change; JSON shapes and exit codes do not. - Be explicit. Pass a visibility flag every time, add
-yto destructive commands, and-qto suppress progress output.
CI pipelines
GitHub Actions: publish build artifacts
name: publish
on:
push:
tags: ["v*"]
jobs:
publish:
runs-on: ubuntu-latest
env:
VELA_URL: https://store.example.com
VELA_KEY: ${{ secrets.VELA_KEY }} # rw key restricted to ci/
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with: { go-version: stable }
- run: go install go.xchunk.org/vela/cmd/vela@v0.9.0
- run: make dist
- name: upload
run: |
vela -q put -r dist/ "ci/releases/${GITHUB_REF_NAME}/" --public --force
vela --json ls -r "ci/releases/${GITHUB_REF_NAME}/" | jq -r '.objects[].url'
Self-cleaning preview builds
Publish a preview per pull request that disappears on its own after a week:
dest="ci/previews/pr-${PR_NUMBER}/"
vela -q put -r ./public "$dest" --unlisted --force --expires 7d
echo "Preview: $(vela url "${dest}index.html")"
Expired files vanish from public URLs immediately and are trashed by the janitor's next pass.
GitLab CI or any other runner
publish:
image: golang:1.27
variables:
VELA_URL: https://store.example.com
script:
- go install go.xchunk.org/vela/cmd/vela@v0.9.0
- vela -q put -r build/ "ci/$CI_COMMIT_REF_SLUG/" --public --force
# VELA_KEY is defined as a masked CI/CD variable
Shell recipes
Does a file exist?
if vela -q stat "backups/$(date +%F).sql.gz" >/dev/null 2>&1; then
echo "today's backup is there"
else
rc=$?
[ "$rc" -eq 3 ] && echo "missing" || { echo "error ($rc)"; exit "$rc"; }
fi
Nightly database dumps with retention
#!/usr/bin/env bash
set -euo pipefail
pg_dump --format=custom app \
| vela -q put - "backups/app/$(date -u +%Y%m%dT%H%M%SZ).dump" --private --expires 30d
The upload streams straight from pg_dump, nothing touches local disk, and each dump self-destructs after 30 days.
Share a file and post the link
url=$(vela -q share "reports/$(date +%Y-%m).pdf" --ttl 7d --note "monthly report")
curl -fsS -X POST "$CHAT_WEBHOOK" -H 'Content-Type: application/json' \
-d "$(jq -n --arg u "$url" '{text: ("This month'"'"'s report: " + $u)}')"
Mirror a local directory
vela -q put -r ./site/ docs/site/ --public --force -j 8
put -r --force uploads and overwrites; it does not delete remote files that no longer exist locally. To remove stale files, compare listings:
comm -13 \
<(cd site && find . -type f ! -path '*/.*' | sed 's|^\./||' | sort) \
<(vela --json ls -r docs/site/ | jq -r '.objects[].path | sub("^docs/site/"; "")' | sort) \
| sed 's|^|docs/site/|' | xargs -r vela rm -y
Delete files older than 90 days
cutoff=$(date -u -d '90 days ago' +%Y-%m-%dT%H:%M:%SZ)
vela --json ls -r logs/ \
| jq -r --arg c "$cutoff" '.objects[] | select(.updated_at < $c) | .path' \
| xargs -r vela rm -y
Inventory report
vela --json ls -r | jq -r '
.objects
| group_by(.visibility)
| map({visibility: .[0].visibility, files: length, bytes: (map(.size) | add)})
| .[] | "\(.visibility)\t\(.files)\t\(.bytes)"'
curl-only recipes
No CLI on the machine? The API is plain HTTP.
export VELA=https://store.example.com/api/v1
auth=(-H "Authorization: Bearer $VELA_KEY")
# upload (create only), with checksum
curl -fsS "${auth[@]}" -X PUT "$VELA/content/ci/build.tar.gz" \
-H "X-Vela-Visibility: private" -H "If-None-Match: *" \
-H "X-Vela-SHA256: $(sha256sum build.tar.gz | cut -d' ' -f1)" \
--data-binary @build.tar.gz | jq .
# small text file
curl -fsS "${auth[@]}" "$VELA/objects" \
-d '{"path": "ci/status.txt", "content": "green\n", "visibility": "public"}'
# download
curl -fsS "${auth[@]}" "$VELA/content/ci/build.tar.gz" -o build.tar.gz
# list
curl -fsS "${auth[@]}" "$VELA/objects?prefix=ci/&recursive=true" | jq -r '.objects[].path'
# signed link valid for one day
curl -fsS "${auth[@]}" "$VELA/links" -d '{"path": "ci/build.tar.gz", "ttl": "1d"}' | jq -r .url
# move and delete
curl -fsS "${auth[@]}" "$VELA/move" -d '{"from": "ci/build.tar.gz", "to": "ci/old/build.tar.gz"}'
curl -fsS "${auth[@]}" -X DELETE "$VELA/objects/ci/old/build.tar.gz"
Remember to percent-encode path segments with spaces or non-ASCII characters, and keep keys out of shell history — read them from a file or a secret store.
Exit codes
| Code | Meaning | Typical reaction |
|---|---|---|
0 | Success | Continue |
1 | Other error | Fail the job |
2 | Usage error | Fix the script |
3 | Not found | Often expected — handle it |
4 | Conflict / exists / precondition | Use --force or re-read |
5 | Auth (401/403) | Check the key and its prefix |
6 | Network / unavailable | Retry later |
7 | Partial success | Inspect the JSON error's details.failed |