Skip to Content

Deploy from CI

Deploy from a CI job with stackblaze up --ci --wait, read its JSON-lines output and exit code, or start a build with the HTTP API.

A CI job can deploy with the same stackblaze up you run locally. With --ci it prints one JSON object per line and exits non-zero when the deploy fails, so the job fails with it.

You don't need this for an app that builds from GitHub with Autodeploy on: StackBlaze already deploys every push (see Deploy from GitHub). Use CI when you want to deploy only after your tests pass, or from a folder or an image your job builds.

Make a token

The job signs in with an API token in STACKBLAZE_TOKEN; it doesn't run stackblaze login. Create one in Personal settings → API tokens (see API tokens), or with the CLI. The CLI prints the token once, so pipe it straight into your CI's secret store. With the GitHub CLI:

stackblaze tokens create ci --expires 90d --json | jq -r .token | gh secret set STACKBLAZE_TOKEN

--expires takes a lifetime (30d, 12h, 2w, 1y) or a date (2027-01-31). The default is 30d. The token acts as you, in the organization it was created in.

Tell the CLI which app

A CI checkout has no .stackblaze/project.json unless you commit it, so name the app with variables (or flags):

VariableFlagWhat it is
STACKBLAZE_TOKEN--tokenThe API token
STACKBLAZE_PIPELINE-p, --projectThe project
STACKBLAZE_PHASE--phaseThe environment (default production)
STACKBLAZE_APP--name, -aThe app

STACKBLAZE_APP can be the name you gave the app (web) or its full name with the suffix (web-0p8g). When we ran up with STACKBLAZE_APP=ci-demo twice, the first run created the app as ci-demo-0p8g and the second updated it. A flag wins over a variable, and a variable over the link file.

up uses --env for KEY=value variables, so the environment is --phase there.

A GitHub Actions workflow

This workflow runs your tests on every push to main, then deploys:

.github/workflows/deploy.yml
name: Deploy
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      STACKBLAZE_TOKEN: ${{ secrets.STACKBLAZE_TOKEN }}
      STACKBLAZE_PIPELINE: my-project
      STACKBLAZE_PHASE: production
      STACKBLAZE_APP: web
    steps:
      - uses: actions/checkout@v4

      - run: npm ci && npm test

      - name: Install the StackBlaze CLI
        run: |
          curl -fsSL https://www.stackblaze.com/install.sh | sh
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"

      - name: Deploy
        run: stackblaze up --ci --wait
  • The install script puts the CLI in ~/.local/bin; the GITHUB_PATH line puts that on the PATH for the next steps.
  • --wait waits until the new version is running, up to 10 minutes (--timeout <seconds> changes it).
  • Re-running up on every push is safe: an existing app is updated and redeployed. Settings it detected when it created the app (the Dockerfile port, the build strategy) aren't changed again.

Which commit gets built

Keep actions/checkout. When up rebuilds an app that builds from git, it pins the build to the commit the job is running for: the pull request's head commit on a pull_request event, otherwise GITHUB_SHA. It reads the same from other CI systems (CI_COMMIT_SHA or CI_MERGE_REQUEST_SOURCE_BRANCH_SHA, BUILDKITE_COMMIT), and falls back to git rev-parse HEAD if that commit has been pushed.

The build isn't pinned when you pass --branch or --repository, and the very first build of a new app uses the head of the branch.

If the folder has no git remote, or you pass --local, up uploads the folder from the job instead (see Deploy a folder).

An image you build in CI

If the job builds and pushes an image, deploy that tag:

stackblaze up --ci --wait --image ghcr.io/acme/web --tag "$GITHUB_SHA"

--tag sets the tag when --image has none. A tag in both that doesn't match is an error. A private registry needs its credentials first (see Private registry).

What --ci prints

stdout gets one JSON object per line. Notices and the upload progress go to stderr, so stdout stays machine-readable. These are the lines from a run against a new app, shortened:

{"type":"deploy","pipeline":"my-project","phase":"dev","app":"ci-demo-0p8g","displayName":"ci-demo","mode":"upload","action":"created",…}
{"type":"build","build":"ci-demo-0p8g-my-project-20261125-073253-29ab","state":"Unknown"}
{"type":"build","build":"ci-demo-0p8g-my-project-20261125-073253-29ab","state":"Active"}
{"type":"log","build":"ci-demo-0p8g-my-project-20261125-073253-29ab","container":"fetch","message":"downloaded 332 bytes"}
…
{"type":"build","build":"ci-demo-0p8g-my-project-20261125-073253-29ab","state":"Succeeded","success":true}
{"type":"status","pipeline":"my-project","phase":"dev","app":"ci-demo-0p8g","phaseStatus":"running","url":"https://ci-demo-0p8g.….stackblaze.app","ready":true}
typeWhenFields
deployOnce, when the deploy startspipeline, phase, app, displayName, mode (upload, git or docker), action (created or updated), and the upload's details
buildEach time the build's state changesbuild, state (Active, Succeeded, Failed, …); the last one also has success
logEach build log linebuild, container (the build step, for example fetch, build, push, deploy), message
statusWith --wait, at the endphaseStatus, url, ready
errorWhen the deploy failsmessage

An image deploy without --wait has no build to follow and ends with {"type":"status","state":"submitted","ready":null}.

When we made the build fail (an npm build script that exits 1), the build logs showed the failing step and the run ended with:

{"type":"build","build":"ci-demo-0p8g-my-project-20261125-073633-eacb","state":"Failed","success":false}
{"type":"error","message":"Build ci-demo-0p8g-my-project-20261125-073633-eacb Failed"}

and exit code 1. The app kept running its previous version.

The CLI follows the build's live log stream. If the stream isn't available it polls instead, with the same lines; STACKBLAZE_BUILD_STREAM=poll forces polling.

Exit codes

CodeMeans
0Deployed (and, with --wait, running)
1The build failed, the app didn't become ready in time, a usage error, or a question the CLI couldn't ask (no terminal)
2No token, or the token is wrong or expired (401)
3The API refused or couldn't be reached: no permission (403), a plan limit (402), a network error or a timeout

The same codes apply to every command. See Scripting and CI for the rest of the CLI's behaviour in scripts.

Build limits

Your plan sets how many builds can run at the same time in your organization, and how long one build may take:

Free TrialDeveloperProBusiness
Builds at the same time12510
Build timeout10 minutes30 minutes60 minutes90 minutes

A build over the limit isn't queued: it's refused with "Your plan runs 1 build at a time and one is running. Try again when it finishes, or upgrade to build more at once." (HTTP 402, so the CLI exits with 3). A new build for an app that is already building doesn't count against the limit: it replaces that app's running build.

Start a build with the API

Without the CLI, start a build with one request. The token needs permission to change the app (app:write):

curl -X POST \
  -H "Authorization: Bearer $STACKBLAZE_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"commitSha\":\"$GITHUB_SHA\",\"message\":\"Deploy from CI\"}" \
  https://api.stackblaze.cloud/api/deployments/build/my-project/production/web

The path is /api/deployments/build/{project}/{environment}/{app}, with the app's full name. Every field in the body is optional; {} builds the app as it's set up. For an app deployed from a folder, it rebuilds the last upload.

Field
commitShaBuild this commit
referenceBuild this branch or tag instead of the app's branch
messageA message for the deploy, shown in Deployment and stackblaze deployments list instead of the commit subject. Up to 500 characters; longer ones are cut.

The answer is 201 with {"message":"Build started", …}.

To follow it, GET /api/deployments/{project}/{environment}/{app} lists the app's builds, newest first. Each has a state (Active while it runs, then Succeeded or Failed) and a deploymentStatus (for example building, build_failed or live). The CLI's stackblaze builds trigger does the same request.

No deploy hooks

StackBlaze has no deploy-hook URLs: there is no secret URL that starts a deploy without a token. Use Autodeploy, stackblaze up --ci or the build API with a token.

On this page