Skip to content

Stages and gates ​

Stages give a pipeline its shape. Each stage is a step that a release moves through, commonly one environment such as dev or prod.

Ordering stages with from ​

A stage with no from is an entry stage. Every other stage lists its upstream stages:

typescript
const dev = new delivery.Stage("dev", { pipeline });
const staging = new delivery.Stage("staging", { pipeline, from: [dev] });
const prod = new delivery.Stage("prod", { pipeline, from: [staging] });

A stage with several upstream stages waits until the same release has succeeded in each of them. Stage names must be unique within a pipeline.

A stage deploys one run at a time. When a newer run reaches a stage while an older run is still waiting for it, or waiting at its gate, the newer run takes its place. A run that has already entered the stage keeps it until it finishes.

INFO

Pulumi Delivery doesn't detect cycles between stages. A run in a cycle waits until you cancel it.

Gates ​

A gate is a rule on a stage that defines when a pipeline can progress. A release can't enter the stage until the rule passes.

Pulumi Delivery supports three kinds of gates, manual, approval, and decision, and you can combine them into one rule. All of them are set in the stage's when property. Anyone with permission to approve the pipeline's runs can continue a manual gate. An approval gate names the people or teams who must approve and how many approvals it needs, shows them a preview of the changes, and lets them reject the release. A decision gate has TypeSafe's Jev model evaluate that preview against questions you write, and rejects the release if the risk is higher than you allow.

Manual gates ​

Manual gates pause the pipeline and wait for a person to continue them. You can use the gate's description property to help that person decide whether to do so:

typescript
const prod = new delivery.Stage("prod", {
    pipeline,
    from: [staging],
    when: delivery.manual({ description: "Check the staging dashboards first." }),
});

Gates can be continued from the run page in the Pulumi Cloud console or with the REST API. See Continuing a gate with the REST API for details.

Approval gates ​

Approval gates (available in the Pro and Enterprise editions) pause the pipeline until a set number of specified users or team members allow it to continue. List them in approvers as Pulumi usernames or team names, and set count to the number of approvals required (one by default):

typescript
const prod = new delivery.Stage("prod", {
    pipeline,
    from: [staging],
    when: delivery.approval({ approvers: ["platform-leads"], count: 2 }),
});

Before approving, an approver sees a preview of the stack updates the stage will make. The preview doesn't cover jobs, because they run arbitrary commands. It can also be incomplete: a stack whose preview shows "Not available" might still change when the stage runs.

Decision gates ​

A decision gate evaluates whether a release can enter a stage based on the risk tolerance you define. It uses TypeSafe's Jev model to answer a set of yes-or-no questions about the stage's preview, and for each question, you set the highest risk you'll accept that the answer is yes. If any answer is riskier than you allow, the gate rejects the release and the run fails.

A decision gate evaluates only the preview of the stack updates the stage will make, so the stage needs at least one Stacks resource. Jobs, artifacts, and agent responses aren't part of the preview. Delivery gives the preview to Jev automatically.

For example, this gate stops a release if Jev thinks the prod stack updates delete a database:

typescript
const prod = new delivery.Stage("prod", {
    pipeline,
    from: [staging],
    when: delivery.decision({
        questions: {
            dataLoss: {
                instructions: "Does the preview delete or replace a database or storage bucket?",
                maximumRisk: 0.05,
            },
        },
    }),
});

new delivery.Stacks("prodServices", {
    stage: prod,
    stacks: {
        api: { stack: "shop-api/prod", source: repo, directory: "api" },
    },
});

For each question, Jev estimates the probability that the answer is yes. Delivery compares that estimate with the question's maximumRisk, a number from 0 to 1, and the gate passes only when every question is at or below its threshold.

WARNING

If the stage's preview is larger than Jev's context window, the gate rejects the release and the run fails.

Combining rules ​

You can also build composite rules that combine manual, approval, and decision gates. In the following example, the pipeline is paused until <your-colleague> approves and someone continues the dashboards check:

typescript
const prod = new delivery.Stage("prod", {
    pipeline,
    from: [staging],
    when: delivery.allOfOutput({
        rules: [
            delivery.approvalOutput({ approvers: ["<your-colleague>"] }),
            delivery.manualOutput({ name: "dashboards", description: "Check the dashboards first." }),
        ],
    }),
});

Composite rules can be of type all or any. all-type rules require that every rule in the rules list be satisfied, as in the previous example. any-type rules require at least one of them to be. You can nest rules up to three levels deep, counting the rules themselves: an all rule that contains an any rule that contains an approval is the deepest a gate can go.

Every rule takes an optional name, and names must be unique within a gate. An approval rule's name defaults to approval and a manual rule's to manual, so name each rule when a gate has two of the same kind.

Continuing a gate with the REST API ​

Any credential with write access to the pipeline stack can continue a manual gate. To do it from another system, such as a deployment hook:

  1. Read the run with GET /api/preview/stacks/<org>/<project>/<stack>/delivery/runs/<run-number>.

  2. In stages, find the stage. If stages[].gate.status is open, note stages[].gate.id.

  3. Send POST .../delivery/runs/<run-number>/gates/<gate-id>/continue with a JSON body:

    bash
    curl -X POST \
        -H "Authorization: token $PULUMI_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{}' \
        https://api.pulumi.com/api/preview/stacks/acme/shop-delivery/main/delivery/runs/<run-number>/gates/<gate-id>/continue

A gate with one manual rule takes an empty JSON object. For a gate with several manual rules, pass the rule's name in condition, as in {"condition": "dashboards"}.

Stage actions ​

A stage normally takes whichever release reaches it next. Stage actions let you intervene when you need to, such as rolling back changes or pausing updates to that stage. You'll find them in the Actions menu on a stage's page in the Pulumi Cloud console or available via API.

Stage actions use your permissions rather than the service principal that deploys the pipeline. To do them, you need write access to the pipeline stack.

Pausing and resuming a stage ​

Pause a stage when you need it to stay on its current release, for example while you investigate a problem in prod. No release enters a paused stage until someone resumes it. A run that's already deploying to the stage finishes, and runs that reach the stage while it's paused wait in its queue.

When you resume the stage, the newest waiting release enters it, as it would have if the stage hadn't been paused.

Rolling back, redeploying, and force-promoting ​

Roll back, redeploy, and force-promote each start a new run that deploys one release to this one stage. The new run reuses the program commit, source commits, and recorded values of the run that first deployed that release, so it repeats what that release did rather than picking up anything newer. It skips the stage's gate and takes priority over other runs waiting for the stage.

  • Roll back deploys a release that's older than the one the stage has now and that the stage already deployed successfully. A rollback also pauses the stage, so the newer release you rolled back from doesn't deploy over it. Resume the stage once you're ready for new releases. Keep in mind that a rollback restores everything in the older release, including any bugs that later releases fixed.
  • Redeploy runs the stage's current release again, with the same commits and values as the run that first deployed it.
  • Force-promote moves a release into the stage without waiting for the stage's gate. The release must already have succeeded in every upstream stage, because the stage reads their outputs. Each force-promote is recorded in your organization's audit log.

You can't roll back to, redeploy, or force-promote a release that came from a local run. When a stage's current release is local, the stage's page shows it as Deployed now with a Local label, alongside its Last cloud release. To replace a local release, roll back to or force-promote a cloud release.

Artifacts ​

Artifacts are to pipelines what stack outputs are to stacks. An artifact is a named value that a stage publishes once the release reaches it, such as a cluster endpoint, a database ID, or a container image tag. Other pipelines in your organization read it with a PipelineSource. Artifacts are how one pipeline hands values to another without either one reaching into the other's stacks.

Publishing an artifact ​

An Artifact resource names the stage that publishes it:

typescript
new delivery.Artifact("clusterEndpoint", {
    stage: prod,
    value: cluster.outputs.apply(o => o["cluster"]["endpoint"]),
});

The value can be any structured value, such as a string, number, list, or map, and it can be secret. An artifact can't hold a file or binary data. It usually comes from the outputs of a stack update or a job in the same stage, as in this example, where cluster is a Stacks resource.

Other pipelines see an artifact once the release reaches its stage and the value is known. Because it belongs to a stage, a downstream pipeline that reads the prod stage only ever sees values from releases that prod deployed.

Reading artifacts from other pipelines ​

A downstream pipeline can read an upstream pipeline's artifacts through a PipelineSource:

typescript
const platform = new delivery.PipelineSource("platform", {
    pipeline: "platform-delivery/main",
    stage: "prod",
    trigger: true,
});

const clusterEndpoint = platform.artifacts["clusterEndpoint"];

Pipeline sources return the artifacts of the latest release the specified stage deployed, including the artifacts that earlier stages published for that release.

Secret artifacts ​

If any artifact is secret, the whole artifacts map is secret. A Stacks entry's config rejects secret values, so pass a secret artifact to a stack update or job in environment instead.

Next steps ​

Content from the official Pulumi documentation (github.com/pulumi/docs).