In Bitbucket Pipelines, how do you make the production deployment step wait for a person, and what actually limits who can run it?
answer
- the step names its environment
- pause before the step
- a pause is not a permission
- permissions sit on the environment
- one deployment per environment at a time
basics
~20 sGive the Bitbucket Pipelines step deployment: production and trigger: manual, so the pipeline pauses until someone promotes it. The pause alone lets anyone with write access deploy; on Premium, deployment permissions restrict each environment to admins or named users and groups.
solid answer
~40 s`deployment: production` ties a step to the Production environment (Test, Staging and Production are created by default), so the run is tracked on the Deployments dashboard and the step receives that environment's **deployment variables**, which override repository and workspace variables of the same name. `trigger: manual` makes the pipeline pause before the step until someone presses Promote, which shows the commits and file changes to be deployed; the first step of a pipeline cannot be manual. The pause is not access control: anyone with write access, who can run pipelines, can promote it. Restricting that is a Premium feature set on the environment: custom deployment permissions for named users and groups, or admins only, and restricting which branches may deploy. Only one deployment per environment runs at a time; later ones are paused.
code
yaml · 15 linespipelines:
branches:
main:
- step:
name: Build
script:
- ./build.sh
artifacts:
- dist/**
- step:
name: Deploy to production
deployment: production
trigger: manual
script:
- ./deploy.sh productiongo deeper
Recall that deployment names the environment and trigger: manual pauses the pipeline before that step.
Explain deployment variables and their precedence, the Promote flow, why the first step cannot be manual, and that only one deployment per environment runs at once.
Show that you separate when from who: the YAML pauses, while environment permissions and branch restrictions on Premium, or repository access on other plans, decide who deploys.
Weigh a human gate on every production deploy against deployment frequency, and what evidence the Deployments dashboard gives an auditor.
## Deployment environments In Bitbucket Pipelines a **deployment environment** is an object in the repository's settings, not just a label in the YAML. When Pipelines is enabled, three are created: **Test**, **Staging** and **Production**. Each can be renamed, given its own **deployment variables**, and, on Premium, restricted. A step (or a stage) joins an environment with the `deployment` keyword: ```yaml pipelines: branches: main: - step: name: Build script: - ./build.sh artifacts: - dist/** - step: name: Deploy to staging deployment: staging script: - ./deploy.sh staging - step: name: Deploy to production deployment: production trigger: manual script: - ./deploy.sh production ``` That buys three things: the deployment appears on the **Deployments dashboard** with its commits, file changes and linked work items; the step gets the environment's **deployment variables**, which override repository and workspace variables of the same name; and the environment's restrictions apply to the step. ## The manual gate: `trigger: manual` `trigger` defaults to `automatic`. Setting `trigger: manual` on a step makes the pipeline **pause** before it, with the deployment shown as *Paused: waiting for manual approval*. A user presses **Promote**, reviews a preview of the commits and file changes, and confirms. Two rules follow from how it works: 1. The **first step of a pipeline cannot be manual**, because a pipeline starts on a commit; the gate always follows at least one automatic step. 2. The paused step will need the artifacts of earlier steps, and **artifacts are kept for at most 14 days**. A release that waits longer than that has nothing to deploy and needs a fresh pipeline. ## Who may deploy: the controls sit on the environment `trigger: manual` decides *when* the step runs. It says nothing about *who* may press the button. | Control | Where it lives | Plan | What it does | |---|---|---|---| | `trigger: manual` | the step in the YAML | every plan | pauses the pipeline; anyone who can run pipelines (write access) can promote | | Deployment variables | the environment | every plan | values, which can be secured, that only that environment's deployment steps receive | | Deployment permissions | the environment | Premium | *Allow only admins to deploy to this environment*, or *Allow selected users or groups to deploy to this environment* | | Deployment restrictions by branch | the environment | Premium | only the listed branches, such as `main` or `release/*`, may deploy there | Details worth knowing about the Premium permissions: - they are set by a **repository admin**, per environment, for up to **100** users and groups combined; - a user still needs **write access** to run pipelines; read-only users can be listed but cannot trigger; - they **take precedence over scheduled and automated deployments**, which are halted until an approved user resumes them. Without Premium, the realistic protection is everything around the pipeline: who has write access to the repository, and the branch permissions that decide who can change `bitbucket-pipelines.yml` on the branch that deploys. ## Behaviours that surprise teams - **One deployment per environment at a time.** A second deployment to Production while one is in progress is paused automatically until the first finishes or is stopped. - **Environment order is enforced.** In a pipeline that uses several environments, Test steps come before Staging, and Staging before Production; steps of the same type can be ordered freely. - **Parallel groups cannot mix types.** All deployment steps in one parallel set must use environments of the same type. - **Redeploys use old artifacts.** Rolling back by redeploying a previous successful deployment works only while its artifacts are under 14 days old, and on Premium only if the deployment permissions allow it. ## Setting up the gate when moving from another CI system 1. Map each target to a Bitbucket environment and keep the Test, Staging, Production order in the YAML. 2. Move per-target settings and secrets into **deployment variables** on those environments, marked secured where they are credentials. 3. Build once in an automatic step, pass the output as an artifact, and put `trigger: manual` only on the production step. 4. On Premium, set deployment permissions and a branch restriction on Production; on other plans, review who has write access and who can change the pipeline file on the deploying branch. 5. Agree that approvals happen within the 14-day artifact window. The interview answer, then, has two halves: the YAML pauses the pipeline, and the environment's settings decide who can end the pause.
- On Premium, what would you configure on the Production environment besides the manual trigger?Deployment permissions, either admins only or a named list of users and groups, so only they can promote the step; a branch restriction so only `main` or release branches can deploy there; and the production credentials as secured deployment variables, so only Production deployment steps ever receive them.
- A release waited three weeks for approval. Why does promoting it now fail?The production step downloads the artifacts built earlier in the run, and Bitbucket Pipelines keeps artifacts for at most 14 days. After that the step has nothing to deploy. Run a new pipeline to rebuild the artifacts, and keep approvals inside the retention window.
- trigger: manual on its own controls who may deploy to production.
- Deployment variables are visible to every step in the pipeline.
- Two deployments to the same environment can run side by side.
- The first step of a pipeline can be manual, gating the whole run.
- Repository variables override deployment variables with the same name.