Gitlab-ci.yml and build #'s - why do they increment for different stages?

gitlab version: 8.9.5 (community edition)

Given the following gitlab-ci.yml example below, how come the build numbers in the gitlab UI increment for the different stages?

In this example, I have 2 stages and once every single stage completes the CI_BUILD_ID increments even though it part of the a singe build workflow. Is this expected behaviour?

stages:

  • deploy_to_staging
  • deploy_to_prod

deploy_to_staging:
stage: deploy_to_staging
environment: staging
script:
- ./scripts/deploy.sh
when: on_success
only:
- master

deploy_to_prod:
stage: deploy_to_prod
environment: prod
script:
- ./scripts/deploy.sh
when: on_success
only:
- master

Yep, that’s expected behavior. You’re looking for CI_PIPELINE_ID if you want all the builds in a given pipeline to use the same ID. Pipelines are a collection of builds for a given commit (or in the future, merge request), whereas builds are individual jobs that happen to share a commit ID with other builds.

See https://docs.gitlab.com/ce/ci/variables/README.html