Skip to content
Snippets Groups Projects

Implement variables for pipeline workflow rules [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Merged Furkan Ayhan requested to merge 294232-V2-variables-in-workflow-rules into master

What does this MR do?

This is another approach for #294232 (closed). First approach: !50682 (closed).

Refactor has been done before this MR => !57136 (merged)

This MR implements the variables keyword for rules of pipeline workflow. This is only for workflow:rules, the previous MR implemented for job:rules.

  • Added root_variables to Pipeline::Chain::Command to store variables defined in YAML.
    • Initially, assigned result.workflow_attributes[:yaml_variables] in lib/gitlab/ci/pipeline/chain/config/process.rb.
  • Added logic in lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb that applying rules for workflow by changing the root_variables of Pipeline::Chain::Command.
  • We have logic in lib/gitlab/ci/config/entry/processable.rb that merging root variables with job variables.
    • Kept the variables attribute the same for now. It will be removed with #300581 (closed).
    • Added job_variables return only job variables.
    • Added variable_inheritance to handle this in seed/build.
  • Then, added logic in lib/gitlab/ci/pipeline/seed/build.rb to override only variables from root.

Why did I choose this way?

  • Our inherit logic is in lib/gitlab/ci/config/entry/processable.rb.
  • However, we have the result of rules in the "create pipeline" logic and we need that result to override workflow variables.
  • We need to use the variables from the result of rules to override the job variables from the workflow.
  • We know the result of workflow:variables/workflow:rules:variables in seed/build.
  • We need to merge root variables into job variables only if they are a part of "inheritance".
  • Another comment: !52085 (comment 506395096)

Screenshots (strongly suggested)

variables:
  VAR1: my var 1
  VAR2: my var 2

workflow:
  rules:
    - if: $CI_COMMIT_REF_NAME =~ /master/
      variables:
        VAR1: overridden var 1
    - if: $CI_COMMIT_REF_NAME =~ /feature/
      variables:
        VAR2: overridden var 2
        VAR3: new var 3
    - when: always

If the first condition is satisfied, then the total variables will be:

- VAR1: overridden var 1
- VAR2: my var 2

If the second condition is satisfied, then the total variables will be:

- VAR1: my var 1
- VAR2: overridden var 2
- VAR3: new var 3

If no condition is satisfied, then the total variables will be:

- VAR1: my var 1
- VAR2: my var 2

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Furkan Ayhan

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • unassigned @mbobin

  • Furkan Ayhan mentioned in merge request !50682 (closed)

    mentioned in merge request !50682 (closed)

  • Furkan Ayhan changed the description

    changed the description

  • Furkan Ayhan changed title from Draft: New Approach: Implement variables for pipeline workflow rules to Draft: Implement variables for pipeline workflow rules

    changed title from Draft: New Approach: Implement variables for pipeline workflow rules to Draft: Implement variables for pipeline workflow rules

  • Furkan Ayhan mentioned in merge request !52305 (merged)

    mentioned in merge request !52305 (merged)

  • Furkan Ayhan added 1200 commits

    added 1200 commits

    Compare with previous version

  • Furkan Ayhan marked this merge request as ready

    marked this merge request as ready

  • assigned to @mbobin

  • Furkan Ayhan added 1 commit

    added 1 commit

    Compare with previous version

  • Furkan Ayhan added 1 commit

    added 1 commit

    • 05f958bc - Keep existing variables value

    Compare with previous version

  • Marius Bobin
  • Furkan Ayhan added 455 commits

    added 455 commits

    Compare with previous version

  • Furkan Ayhan added 1 commit

    added 1 commit

    • dfe80b11 - Fix webide terminal job variables

    Compare with previous version

  • Marius Bobin
  • Marius Bobin
  • Marius Bobin
  • Marius Bobin
  • unassigned @mbobin

  • Furkan Ayhan changed the description

    changed the description

  • Furkan Ayhan changed the description

    changed the description

  • mentioned in issue #300581 (closed)

  • Furkan Ayhan added 430 commits

    added 430 commits

    Compare with previous version

  • Furkan Ayhan changed the description

    changed the description

  • assigned to @mbobin

  • Marius Bobin
  • Marius Bobin
  • unassigned @mbobin

  • assigned to @mbobin

  • Furkan Ayhan added 391 commits

    added 391 commits

    • ae2ec8ec...620bf1c9 - 384 commits from branch master
    • f2289bb6 - Implement variables for pipeline workflow rules
    • f8fde65e - Fix failed tests
    • a56a3894 - Keep existing variables value
    • f752d1a6 - Fix webide terminal job variables
    • 7d2c7fbc - Fix doc and add follow-up issue
    • d9efe3b2 - Move variable inheritance into seed-build
    • 43a9fb60 - Fix default value of variable_inheritance

    Compare with previous version

  • Furkan Ayhan added 1 commit

    added 1 commit

    • e4a21f03 - Fix default value of variable_inheritance

    Compare with previous version

  • Marius Bobin approved this merge request

    approved this merge request

  • unassigned @mbobin

  • mentioned in issue #300997 (closed)

  • Furkan Ayhan changed the description

    changed the description

  • Author Maintainer

    @marcel.amirault Can you please do the documentation review?

  • Furkan Ayhan added 2 commits

    added 2 commits

    • b00b3c5d - Implement variables for pipeline workflow rules
    • ac776b0d - Add the feature flag ci_workflow_rules_variables

    Compare with previous version

  • 🤖 GitLab Bot 🤖 changed title from Implement variables for pipeline workflow rules to Implement variables for pipeline workflow rules [RUN ALL RSPEC] [RUN AS-IF-FOSS]

    changed title from Implement variables for pipeline workflow rules to Implement variables for pipeline workflow rules [RUN ALL RSPEC] [RUN AS-IF-FOSS]

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading