Pages Parallel Deployments randomly override primary deployment.

Summary

GitLab Ultimate customer (Internal ZD link) on GitLab v17.9.0, using documented way of parallel deployment of pages.

Sometimes (completely random), the MR deployment overrides the primary pages deployment, and adds path_prefix

Also, the primary deployment reflects the job ID that performed the MR deployment. And the job's log still shows "Pages accessible through <pages url> and with mr-id path_prefix.

Here are some illustrations from the customer.

https://gitlab.com/-/project/278964/uploads/0bc7cbe8e11f2e6bac611a2f4e7e46b8/Screenshot_2025-03-03_at_11.06.11_AM.png

https://gitlab.com/-/project/278964/uploads/0c5963e7d60221d38b94d12626db2eb0/Screenshot_2025-03-03_at_11.06.47_AM.png

The user reproduced this with the following CI job expression

deploy-pages:
  stage: deploy
  script:
    - echo $CI_COMMIT_REF_NAME
    - sed -i "s|CI_COMMIT_BRANCH|${CI_COMMIT_BRANCH}|g" public/index.html.gitlab
    - echo "Pages accessible through ${CI_PAGES_URL}"

  variables:
    PAGES_PREFIX: "" # no prefix by default (master)
  pages:  # specifies that this is a Pages job and publishes the default public directory
    path_prefix: "$PAGES_PREFIX"
  environment:
    name: "Pages ${PAGES_PREFIX}"
    url: $CI_PAGES_URL
  rules:
    - if: $CI_SERVER_URL == "https://cn-main.gitlab.in.here.com"
      when: never
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_COMMIT_BRANCH == "staging"
    - if: $CI_MERGE_REQUEST_ID
      variables:
        PAGES_PREFIX: 'mr-$CI_MERGE_REQUEST_IID'
    - if: '$CI_MERGE_REQUEST_SOURCE == "schedule"'
    - if: '$CI_MERGE_REQUEST_SOURCE == "web"'
    - if: '$CI_COMMIT_BRANCH == "main"'

I tested multiple times, with and without Merge Results pipelines, with and without rebase, and made different commits. Still, I'm unable to replicate this.

The same happens with the following example:

stages:
  - deploy

pages:
  stage: deploy
  script:
    - echo "My first deploy job for pages."
    - cp public/index.html.gitlab public/index.html
    - echo "Pages accessible through ${CI_PAGES_URL} - ${PAGES_PREFIX}"
  variables:
    PAGES_PREFIX: "ref-$CI_COMMIT_REF_SLUG"
  pages: # specifies that this is a Pages job
    path_prefix: "$PAGES_PREFIX"
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      variables:
        PAGES_PREFIX: ""
    - if: $CI_COMMIT_BRANCH == "staging" # ensure to run on master (with default PAGES_PREFIX)
      variables:
        PAGES_PREFIX: "_stg" # prefix with _stg for the staging branch
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" # conditionally change the prefix on Merge Requests
      variables:
        PAGES_PREFIX: "mr-$CI_MERGE_REQUEST_IID" # prefix with the mr-<iid>, like `mr-123`

Steps to reproduce

Example Project

What is the current bug behavior?

What is the expected correct behavior?

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

 (For installations with omnibus-gitlab package run and paste the output of: \`sudo gitlab-rake gitlab:env:info\`)  (For installations from source run and paste the output of: \`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\`)  

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:check SANITIZE=true`)

(For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true`)

(we will only investigate if the tests are passing)

Possible fixes