Pages Parallel Deployments randomly override primary deployment.
<!---
Please read this!
Before opening a new issue, make sure to search for keywords in the issues
filtered by the "regression" or "type::bug" label:
- https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression
- https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug
and verify the issue you're about to submit isn't a duplicate.
--->
### Summary
~"GitLab Ultimate" ~customer ([Internal ZD link](https://gitlab.zendesk.com/agent/tickets/609078)) on GitLab v17.9.0, using [documented way of parallel deployment of pages](https://docs.gitlab.com/user/project/pages/parallel_deployments/#use-parallel-deployments-to-create-pages-environments).
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`
```
<!--Summarize the bug encountered concisely.-->
### Steps to reproduce
<!--Describe how one can reproduce the issue - this is very important. Please use an ordered list.-->
### Example Project
<!--If possible, please create an example project here on GitLab.com that exhibits the problematic
behavior, and link to it here in the bug report. If you are using an older version of GitLab, this
will also determine whether the bug is fixed in a more recent version.-->
### What is the current _bug_ behavior?
<!--Describe what actually happens.-->
### What is the expected _correct_ behavior?
<!--Describe what you should see instead.-->
### Relevant logs and/or screenshots
<!--Paste any relevant logs - please use code blocks (```) to format console output, logs, and code
as it's tough to read otherwise.-->
### Output of checks
<!--If you are reporting a bug on GitLab.com, uncomment below-->
<!--This bug happens on GitLab.com-->
<!--and uncomment below if you have /label privileges-->
<!--/label ~"reproduced on GitLab.com"-->
<!--or follow up with an issue comment of `@gitlab-bot label ~"reproduced on GitLab.com"` if you do not-->
#### Results of GitLab environment info
<!--Input any relevant GitLab environment information if needed.-->
<details>
<summary>Expand for output related to GitLab environment info</summary>
<pre>
(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\`)
</pre>
</details>
#### Results of GitLab application Check
<!--Input any relevant GitLab application check information if needed.-->
<details>
<summary>Expand for output related to the GitLab application check</summary>
<pre>
(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)
</pre>
</details>
### Possible fixes
<!--If you can, link to the line of code that might be responsible for the problem.-->
<!--If you don't have /label privileges, follow up with an issue comment of `@gitlab-bot label ~"type::bug"`-->
issue