Skip to content
Latchkey

Bitbucket "Deployments must happen in order"

Bitbucket can enforce environment ordering (Test → Staging → Production). A deploy to a later environment is rejected when the same commit has not been deployed to the required earlier environment first.

What this error means

A deployment to a higher environment is blocked, noting deployments must happen in order. The commit skipped an earlier environment, or that earlier deploy has not run for this build.

bitbucket-pipelines
You can't deploy to "production" because deployments must happen in
order: deploy to "staging" first.

Common causes

Earlier environment not deployed for this commit

Ordered environments require the lower tier to be deployed first. Jumping straight to production without staging is rejected.

Promotion from the wrong build

Deployment ordering tracks the specific commit/build. Promoting a build that never went through the earlier environment trips the order check.

How to fix it

Deploy environments in sequence

Define the deployment tiers in order and promote through them.

bitbucket-pipelines.yml
pipelines:
  branches:
    main:
      - step: { deployment: test, script: [ ./deploy.sh test ] }
      - step: { deployment: staging, trigger: manual, script: [ ./deploy.sh staging ] }
      - step: { deployment: production, trigger: manual, script: [ ./deploy.sh prod ] }

Promote the build that passed earlier tiers

  1. Confirm the commit was deployed to the required earlier environment.
  2. Promote that same build forward rather than a different one.
  3. Adjust the environment ordering settings if the policy is wrong.

How to prevent it

  • Promote builds through environments in the configured order.
  • Deploy the same commit forward rather than skipping tiers.
  • Keep environment ordering settings aligned with your release process.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →