Can we use "only" instead of "rules" in gitlab?

Viewed 542

In my gitlab ci/cd script , we are using rules

workflow:
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "developer" || $CI_COMMIT_BRANCH == "stage"|| ($CI_COMMIT_BRANCH =~ (/^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?)+/i))
      when: always
    - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH != "developer" || $CI_COMMIT_BRANCH != "stage"|| ($CI_COMMIT_BRANCH !~ (/^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?)+/i))
      when: never 

for specific job , we are using only

only:
  - developer
  - stage

FINE. but I want the scenerio like

only:
  - developer
  - stage
  - (/^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?)+/i))

the sprint which I used is not working . If I use "rules" , its working , but I want "only" to be used in my script . Please help me to sort it out this.

1 Answers

An only: directove does support regular expressions that match against branch names.

But the syntax is like /^feature-.*/, so check if the outer () are in the way.

Plus, there seems to be an imbalance in the 5 ( vs. 6 ).

So either:

 (/^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?)+/i)

Or

 /^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?)+/i
Related