Variable the only:ref in gitlab ci yaml file

Describe your question in as much detail as possible:
We are using only:ref in our pipelines,

.project_a_conditions_only:
  only:
     refs:
       - /^(.+\/(bug|story|task)\/.+)|(.+\/(revert|patch)\/.+)/
     variable:
       - $PROJECT_A

I’m trying to convert the above into

variables:
  - BRANCH_REF_REGEX = /^(.+\/(bug|story|task)\/.+)|(.+\/(revert|patch)\/.+)/
.project_a_conditions_only:
  only:
     refs:
       - $BRANCH_REF_REGEX
     variable:
       - $PROJECT_A

The above syntax is not working as expected. Can we make the above way work? When I change GitLab ci yml config to the above, I could not see my job anymore in the pipeline.

  • What version are you on? Are you using self-managed or GitLab.com?

    • GitLab (Hint: /help): 14.8.5-ee
    • Runner (Hint: /admin/runners): 14.10.0
  • What troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?
    Choose when to run jobs | GitLab

Thanks for taking the time to be thorough in your request, it really helps! :blush:

Hi @gvreddy579

you need to use rules: to achieve that.