Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab FOSS GitLab FOSS
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1
    • Merge requests 1
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLab FOSSGitLab FOSS
  • Issues
  • #62867
Closed
Open
Issue created Jun 06, 2019 by Brendan O'Leary 🐢@brendan🌻Developer

Add AND and OR operators for variable expressions in GitLab CI/CD

Problem to solve

only/except are powerful primitives, but today are limited to only one case - either a single condition such as

job:
  # use regexp
  only:
    - /^issue-.*$/
  # use special keyword
  except:
    - branches

Adding multiple items does an "implied OR" such that

job:
  # use regexp
  only:
    - /^issue-.*$/
    - master

Will build on branches that match the RegEx OR the master branch

Intended users

  • Persona: DevOps Engineer
  • Persona: Development Team Lead

Further details

This will be an excellent iteration for more complex use cases for only/expect, but will not be as wide of a solution as the flexible ruleset. Both will have impacts on how users can control which jobs run when, but have points where both are useful

Proposal

Allow a user to specific AND and OR conditions explicitly in a variable expression.

Use a well-known pattern of && for AND and || for OR. This will produce the ability for use cases such as:

Run on a job on master - AND on tags

job:
  stage: publish
  script:
    - ./do-publish.sh  
  only:
    - tags && master

Run a job on based on two different variables

  only:
    - $VARIABLE1 =~ /^content.*/ || $VARIABLE2 =~ /thing$/

Complex logic with AND and OR

  only:
    - $VARIABLE1 =~ /^content.*/ || $VARIABLE2 =~ /thing$/ && $VARIABLE3

Permissions and Security

This will not change anything about the permissions or security for variables or the .gitlab-ci.yml

Documentation

This will require a documentation update with details AND clear examples.

Testing

What does success look like, and how can we measure that?

Links / references

Edited Jun 10, 2019 by Brendan O'Leary 🐢
Assignee
Assign to
Time tracking