Skip to main content
You do not need to build on Levelrail. Your CI builds and pushes an image to a registry, then tells Levelrail to deploy it and waits for the result. Levelrail only hosts. On a runner with Node, get the CLI with npx levelrail-cli@<version> <command> or npm install --global levelrail-cli@<version> (details). It is the client only, not the server.

The three steps

  1. Install the CLI in the job, or call the API directly. The installer is curl -fsSL https://levelrail.com/install-cli.sh | sh. Set LEVELRAIL_CLI_INSTALL_DIR to a directory you can write to (the default is /usr/local/bin for root and ~/.local/bin otherwise) and LEVELRAIL_VERSION=vX.Y.Z to pin a release.
  2. Authenticate with environment variables only. LEVELRAIL_API_URL is your control plane URL and LEVELRAIL_TOKEN is an API token with at least the deploy ability. LEVELRAIL_PROFILE picks a saved profile and is not needed in CI. The CLI also reads CI=true (or LEVELRAIL_CI=true) and then never prompts, and it does so by itself when stdin or stdout is not a terminal.
  3. Deploy by image, then wait. apps deploy returns as soon as the deploy is accepted. apps wait is what tells you whether the rollout worked.
apps deploy requires --image here; add --confirm to deploy into a protected environment. apps wait also takes --attempt-id and --poll-interval (default 3s). On GitHub Actions, GitLab CI and CircleCI you can skip the stored token and use OIDC instead. Elsewhere, create the token once and store it in your CI’s secret store:

Least-privilege token

When you cannot use OIDC, give the CI the smallest token that can deploy. The deployer preset grants read and deploy only, so the token cannot read secrets or change settings. Add a short expiry and, if you use teams, limit it to one project:
The token is shown once. Store it in your CI’s secret store as LEVELRAIL_TOKEN and rotate it before it expires. See Teams and roles for what a scope allows.

Roll back on failure

apps wait exits 5 when the deploy converged as a failure and 6 on timeout. To go back to the previous successful deploy, run this in a step that only runs when the deploy step failed:
Without --image, apps rollback picks the newest earlier successful deploy. It returns as soon as the request is accepted, so check apps status to see that it landed. In a shell script:
On GitHub Actions use if: failure() on a step after the deploy step. On GitLab CI use after_script or a job with when: on_failure. On CircleCI use when: on_fail. On Jenkins use post { failure { ... } }. On Buildkite run the script above in the same step. Rolling back needs the same deploy ability as deploying.

Exit codes

Branch on these in scripts. A job running apps deploy then apps wait fails on any non-zero code, which is what you want.

Safe retries

apps deploy sends an Idempotency-Key, so re-running the same job applies the deploy once and replays the first result. The CLI derives the key from the app, the image and the run id. It reads only two sets of run variables: GITHUB_RUN_ID with GITHUB_RUN_ATTEMPT, and CI_PIPELINE_ID (set by GitLab CI). On any other CI it falls back to the current minute, so pass your own key from the CI’s build id:
The CLI retries HTTP 429 and 503 for requests that carry an idempotency key, waiting for Retry-After. LEVELRAIL_RETRY_MAX (default 3, 0 turns retry off) and LEVELRAIL_RETRY_MAX_WAIT (default 60s) bound it. See Deploy from your computer.

Ready-to-copy pipelines

Each file builds an image, pushes it, deploys it pinned by digest and waits for the rollout to be healthy. A test in the CLI parses every file and fails if a command or flag it uses no longer exists, so they stay current. Each file needs a CI trust on the app once (see OIDC support). The job then runs levelrail-cli apps ci token my-app --provider <github|gitlab|circleci>, which swaps the job’s identity token for a deploy token that expires after 15 minutes. On GitLab and CircleCI the token is read from LEVELRAIL_ID_TOKEN, or from the variable named by --id-token-env. apps github-actions token and apps github-actions trust still work as deprecated aliases of apps ci token and apps ci trust.

Deploy by digest from a build-complete hook

If your CI already built and pushed the image and you would rather call the API than install the CLI, send the deploy straight to the same endpoint apps deploy uses. There is no separate webhook to set up:
  • image takes name:tag, name@sha256:digest or name:tag@sha256:digest. Pin by digest so a re-pushed tag can never change what runs.
  • The token needs the deploy ability on the app, the same as the CLI. An OIDC exchange token from GitHub, GitLab or CircleCI works here too.
  • The Idempotency-Key makes a retried hook apply once: a repeat with the same key and body within 24 hours replays the first response, and the same key with a different body is refused.
  • Deploy freezes, protected environment approvals (add "confirm": true), deploy policies and rate limits apply exactly as they do to any other deploy, and the call is recorded in the audit log.
  • A 202 means accepted. Poll GET /api/v1/apps/my-app/deploy-attempts, or run levelrail-cli apps wait my-app, to learn whether it became healthy.
The CLI equivalent is levelrail-cli apps deploy my-app --image registry.example.com/team/my-app@sha256:<digest>.

OIDC support

A CI trust lets one pipeline identity deploy one app. The exchange endpoint (POST /api/v1/ci/oidc-exchange) verifies the job’s identity token, finds a trust on the app that matches it, and returns a token that can only read and deploy that app for 15 minutes. With no matching trust the answer is 403 and nothing is granted.
The same fields go to POST /api/v1/apps/{name}/ci/trusts as provider, issuer, org_id, repository, ref_pattern, environment and protected_ref_only. How tokens are checked:
  • Issuers are an allowlist. GitHub’s issuer is fixed. A GitLab or CircleCI token is only considered when its iss equals, exactly, the issuer of a trust on that app (https://gitlab.com, your self-managed URL, or https://oidc.circleci.com/org/<ORG_ID>). Keys are fetched from that configured issuer (<issuer>/oauth/discovery/keys on GitLab, <issuer>/.well-known/jwks-pub.json on CircleCI), never from a URL inside the token.
  • Audience. The token’s aud must be the dashboard URL set in Settings. Set it in id_tokens on GitLab, and with circleci run oidc get --claims '{"aud":"..."}' on CircleCI (the default CircleCI token’s audience is the organization ID, which is refused).
  • Signatures. Only RS256 and ES256 are accepted, the token must name its key with kid, and exp, nbf and iat are checked.
  • Key fetching uses https only, refuses hosts that resolve to private, loopback or link-local addresses, does not follow redirects to other hosts, and refetches on an unknown key at most once per refresh interval.
  • GitLab safe defaults. A GitLab trust accepts only protected branches and tags (ref_protected), unless it is created with --no-protected-ref (API: "protected_ref_only": false); the response then carries a warning, because any developer who can push a matching branch or tag could deploy. Pipelines with pipeline_source merge_request_event or external_pull_request_event are always refused, since a merge request from a fork can run in the parent project with its project path and a branch named main. When the trust names an environment, the token must also carry environment_protected: true, because any job can declare an environment.
  • Who may add a trust. The caller needs write:sensitive and deploy on the app, so a trust never grants more than its creator holds. A self-managed GitLab issuer (anything other than https://gitlab.com) needs a root user, since whoever runs that issuer can mint tokens.
  • Token age. Tokens older than APP_CI_OIDC_MAX_TOKEN_AGE (default 1h) are refused, and so are tokens without iat while a maximum age applies.
  • Audit. Trust create and delete write ci_oidc_trust.created and ci_oidc_trust.deleted audit entries with the provider and issuer. Every issued token writes ci_oidc_exchange.issued; refusals write ci_oidc_exchange.refused with the reason, at most one row per app, provider and reason per APP_CI_OIDC_AUDIT_WINDOW (default 1m, with a suppressed count). Entries carry the app, provider and a hash of the subject, never the token.
  • Logs carry the app, the trust ID and a shortened subject, never the token.
These variables apply to GitLab and CircleCI. GitHub tokens are verified as before. Buildkite OIDC is not accepted yet; use an API token there.

Stacks

Stack trusts (POST /api/v1/stacks/{name}/oidc-trusts, root only) take the same provider, issuer, org_id and protected_ref_only fields and the same checks as app trusts, for plan and apply from GitLab CI and CircleCI. An apply trust additionally needs an exact branch or tag ref and an environment (a protected one on GitLab), and a GitLab apply trust always requires protected refs; a plan-only GitLab trust may opt out and then returns the warning. Merge request pipelines are refused. Create and exchange write stack.oidc_trust_create and stack.oidc_exchange audit entries with the provider and issuer. Stack trusts have no CLI command yet; use the API.

Downgrading

Rolling back to v0.8.8 or earlier makes the older control plane ignore the provider column, so it would treat a GitLab or CircleCI trust row as a GitHub trust on the same path. Delete every non-GitHub trust (apps ci trust list then trust remove) before you downgrade.

GitLab CI

Set LEVELRAIL_API_URL under Settings > CI/CD > Variables (not a secret). Add the trust once, then request an ID token for the control plane in the job.
CI_PIPELINE_ID is read for the idempotency key, so no extra flag is needed. The control plane must be able to pull $IMAGE, so add the registry credentials to the app first. To keep using an API token instead, store it as a masked, protected variable LEVELRAIL_TOKEN and drop the id_tokens block and the token lines.

CircleCI

Put LEVELRAIL_API_URL in a context (here levelrail) and require that context’s ID in the trust with --environment.

Jenkins

Create two Secret text credentials with the ids levelrail-api-url and levelrail-token under Manage Jenkins > Credentials. The complete Jenkinsfile is ci-examples/token/jenkins.groovy; the dashboard shows the same file for your app under Deploy settings, and levelrail-cli apps ci template my-app jenkins prints it. The single-quoted sh strings keep Groovy from interpolating the secrets into the command line, and Jenkins masks the credential values in the log.

Buildkite

Keep the secrets in your agent environment hook, a secrets manager plugin, or Pipeline Settings. Do not put them in pipeline.yml. The complete pipeline is ci-examples/token/buildkite.yml; levelrail-cli apps ci template my-app buildkite prints it for your app. $$ stops Buildkite from expanding the variable at upload time. LEVELRAIL_API_URL and LEVELRAIL_TOKEN must already be in the step’s environment.

Troubleshooting

Next steps

Last modified on November 8, 2026