Manual pipeline prefilled variables always load from the default branch and not the selected ref

Summary

When manually running a pipeline from the UI, the prefilled variables are fetched from the default branch, even when a different branch or tag is selected. This causes pipelines on feature branches or tags to start with variable values that don’t match the configuration in that ref. The correct values from the selected ref are only used if the user removes the variable first.

Related issue: #520211

Steps to reproduce

  1. Create a project with the following .gitlab-ci.yml on the default branch.

    variables:
      TEXT:
        value: MAIN-VAR
        description: desc
    
    build:
      script:
        - echo "TEXT : ${TEXT}"
  2. Create a new branch feature, and change the variable.

    variables:
      TEXT:
        value: FEATURE-VAR
        description: desc
    
    build:
      script:
        - echo "TEXT : ${TEXT}"
  3. Ensure variable overrides are enabled for the project:

    Go to SettingsCI/CDVariables"Minimum role to use pipeline variables"

  4. In the UI, manually start the pipeline:

    Go to BuildPipelinesNew Pipeline, then select the feature branch at the top.

  5. Observe that the prefilled variable TEXT loads with the value "MAIN-VAR" from the default branch instead of "FEATURE-VAR".

    Screenshot 2025-12-02 at 20.02.22.png

  6. Running the pipeline on the feature branch results in this variable being overridden with the incorrect value.

Example Project

What is the current bug behavior?

Prefilled variables always show the value from the default branch, regardless of which branch or tag is selected.

What is the expected correct behavior?

Prefilled variables should load the values defined in the selected branch or tag.

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

Patch release information for backports

If the bug fix needs to be backported in a patch release to a version under the maintenance policy, please follow the steps on the patch release runbook for GitLab engineers.

Refer to the internal "Release Information" dashboard for information about the next patch release, including the targeted versions, expected release date, and current status.

High-severity bug remediation

To remediate high-severity issues requiring an internal release for single-tenant SaaS instances, refer to the internal release process for engineers.

Edited by Keith Afwande