Skip to content

GitLab Next

    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Menu
    Projects Groups Snippets
  • Get a free trial
  • Sign up
  • Login
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 42,996
    • Issues 42,996
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,354
    • Merge requests 1,354
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.org
  • GitLabGitLab
  • Issues
  • #294232
Closed
Open
Created Dec 17, 2020 by Furkan Ayhan@furkanayhan💡Maintainer

Support `variables` for workflow `rules`

This is a follow-up issue from #209864 (closed).

Copied from that issue:

Release notes

Previously, the rules keyword was limited in scope and only determined if a job should be included or excluded from pipelines. Lately we've added the ability to override variables in a job, In this release, we've extended this ability so you can now decide if certain conditions are met and subsequently override pipeline variables, providing you with more flexibility when configuring your pipelines.

Problem to solve

Rules define when certain jobs can be run, but they could also provide overrides for configuration. This would be a handy way to set up rules for when certain policies or variables should be set. One example use case would be making cache-policy settable by “rules” to say for example that you only want to update the cache pull-push on master and not on branches. Another could be setting interruptible using various rules.

Intended users

  • Devon (DevOps Engineer)

Proposal

In this issue, we only add variables to the workflow rules.

Add variables to rules to specify variables. To use the example from the problem to solve section, this would look like:

workflow:
  variables:
    MY_VAR: "initial value"
  rules:
    - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
      variables:
        MY_VAR: "hello"
job1:
  variables:
    DEPLOY_VARIABLE: "job1-default-deploy"
  rules:
    - if: $CI_COMMIT_REF_NAME =~ /master/
      variables:                                   # Override DEPLOY_VARIABLE defined
        DEPLOY_VARIABLE: "job1-deploy-production"  # at the job level.
    - when: on_success                             # Run the job in other cases
Edited Apr 13, 2021 by Dov Hershkovitch
Assignee
Assign to
Time tracking