Webhook icon
Schedule icon
Script icon
Request icon
LoopUntil icon
If icon
Create icon
SlackIncomingWebhook icon
Fail icon
Log icon

Preview Deploy Gate for Vercel with Build Budget Checks

Create a Vercel preview deployment on every push, poll it to READY, and gate on build budget with a GitHub issue and a Slack alert in Kestra.

Categories
CoreInfrastructure

Preview deployments are easy to create and easy to ignore. A push lands, Vercel builds for three minutes, the URL shows up in a comment, and nobody notices when the build broke or when the same preview has been eating build minutes for an hour. This blueprint makes the preview a gate. A webhook fires on push, a Python step reads the repository, branch, commit SHA, and actor out of the payload, and a Vercel deployment is created with the git source pinned to that exact SHA, so the preview URL always belongs to the commit under review. The flow then polls the deployments API until Vercel reports READY or ERROR, scores the result against a build time budget, and turns a bad outcome into three signals at once: a labeled GitHub issue carrying the preview URL and the reasons, a Slack notice, and a failed execution that whatever pipeline watches this flow can act on.

How it works

  1. The on_push trigger (io.kestra.plugin.core.trigger.Webhook) exposes a keyed URL for your git host or CI to POST the push payload to, and the nightly_replay Schedule trigger ships disabled as an optional safety net.
  2. parse_push_payload (io.kestra.plugin.scripts.python.Script) reads the payload from an input file and extracts repo, repo_owner, repo_name, branch, commit_sha, and actor, falling back to the repository input so a manual run still produces a usable deployment.
  3. create_deployment (io.kestra.plugin.core.http.Request) calls POST https://api.vercel.com/v13/deployments with Authorization: Bearer built from the VERCEL_TOKEN secret, target: preview, and a gitSource object carrying the org, repo, ref, and commit SHA.
  4. wait_until_ready (io.kestra.plugin.core.flow.LoopUntil) polls GET /v13/deployments/{id} every 10 seconds for at most 30 checks, about 5 minutes, and stops as soon as readyState is READY or ERROR; the bound is deliberate, so a hung build cannot hold the execution open forever.
  5. assess (io.kestra.plugin.scripts.python.Script) compares readyState against READY, measures the build with Vercel's duration.timeToReady (falling back to createdAt against ready) versus the budget_seconds input, and emits verdict, reasons, the preview URL, and a checks summary through the outputs protocol.
  6. gate (io.kestra.plugin.core.flow.If) branches on that verdict. On failure, open_issue (io.kestra.plugin.github.issues.Create) files an issue with the preview URL and every reason, alert_slack posts the same summary, and fail_the_run (io.kestra.plugin.core.execution.Fail) turns the execution red. On success, log_preview records the healthy URL and build time.
  7. The errors block alerts Slack when the gate itself breaks, because a dead gate looks exactly like a healthy preview.

What you get

  • A preview URL that is provably tied to the commit that was pushed, not to whatever branch tip happens to exist when someone opens the link.
  • A build time budget expressed as one input, so slow previews become visible instead of silently normal.
  • Escalation where engineers already work: a labeled GitHub issue with the preview URL and reasons, plus a Slack ping.
  • A bounded poll, 30 checks 10 seconds apart, so a wedged build ends in a verdict rather than a hung execution.
  • Typed outputs (deployment_url, state, build_seconds, verdict, reasons) that a parent release flow can branch on, and a dated execution history for every preview.

Who it's for

  • Frontend and full-stack teams shipping to Vercel who want previews reviewed as a gate rather than as a comment.
  • Platform engineers standardizing what a good preview looks like across many repositories.
  • Release managers who need a red execution when a preview build breaks, not a quiet success with a dead URL.
  • Small teams replacing "someone will check the preview" with an enforced, auditable rule.

Why orchestrate this with Kestra

A vercel deploy --prebuilt line in a shell script can create a preview, but it cannot remember the commit, poll with a bound, measure the build against a budget, and escalate on three channels while leaving a typed result for the next stage. Kestra supplies the keyed webhook trigger, the conditional branch, the bounded LoopUntil that turns an asynchronous build into a synchronous step, and an execution record showing exactly which SHA was deployed, how long it took, and why the gate passed or failed. The same logic spread across CI configuration and cron jobs becomes a file you can review, replay with different inputs, and alert on when it itself fails.

Prerequisites

  • A Kestra instance with a worker able to run the python:3.12-slim image for the two script tasks.
  • A Vercel account, a project name to deploy previews for, and an access token with permission to create and read deployments.
  • A GitHub repository the Vercel project is connected to, plus a token that can create issues in it.
  • A git host or CI that can POST the push payload to the webhook URL.

Secrets

  • VERCEL_TOKEN: Vercel access token used for the deployment create and status calls.
  • GITHUB_TOKEN: GitHub token used to open the escalation issue (classic PAT scope repo, or fine-grained Issues write).
  • PREVIEW_DEPLOY_WEBHOOK_KEY: key segment guarding the webhook URL, anyone with it can trigger a deploy, so treat it as a secret.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for gate failures and for failures of the gate itself.

Quick start

  1. Add the four secrets above to your Kestra namespace.
  2. Set project_name to your Vercel project and repository to owner/repo; leave budget_seconds at 300 or tune it to your build times.
  3. Point your git host's push webhook at /api/v1/{tenant}/executions/webhook/{namespace}/vercel-deploy-preview-gate/PREVIEW_DEPLOY_WEBHOOK_KEY, or trigger the webhook by hand with a push payload such as {"ref": "refs/heads/main", "after": "0123456789abcdef", "repository": {"full_name": "your-org/your-repo"}, "pusher": {"name": "dev"}}.
  4. Run the flow once and confirm the preview URL, the build seconds, and the pass verdict on the execution's Outputs tab.
  5. Push a commit that breaks the build, or lower budget_seconds below the real build time, and confirm the GitHub issue, the Slack notice, and the failed execution.

How to extend

  • Raise budget_seconds for monorepos with long builds, or set it to 0 to gate on the ready state only.
  • Fan the gate across many repositories by calling this flow as a subflow per owner/repo from a parent pipeline.
  • Post the preview URL back to the pull request by adding a GitHub comment task next to open_issue.
  • Widen the poll bound by raising maxIterations on wait_until_ready, or tighten it for smoke tests that only need the first response.
  • Store each verdict in Kestra's KV store with io.kestra.plugin.core.kv.Set to trend build times per branch.
  • Route failures to PagerDuty or Jira instead of, or alongside, the GitHub issue.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.