Skip to content

Add new keyword needs to rules

Kasia Misirli requested to merge 31581/Allow_needs_in_jobs into master

What does this MR do and why?

Main issue where the details of this work can be found.
Feature flag rollout issue.

Adding the ability to have needs in rules on builds and bridges.
I added a feature flag to this feature as we need to add docs as well as test some edge cases before a full release.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

With FF enabled:

  1. In rails console enable the feature flag fully or per project
    Feature.enable(:introduce_rules_with_needs, project)
  2. Checkout my branch
  3. Create a project with yml file eg
                 main_job:
                  script: 'echo job'
                  needs: [rspec_job]
                  rules:
                    - if: $var == null
                      needs: [lint_job, rspec_job]
                lint_job:
                  script: 'echo lint_job'
                  rules:
                    - if: $var == null
                      needs: [rspec_job]
                rspec_job:
                  script: 'echo rspec_job'
                  rules:
                    - if: $var == null

or

                 main_job:
                  script: 'echo job'
                  needs: [rspec_job]
                  rules:
                    - if: $var == null
                      needs: 
                        - job: lint_job
                        - rspec_job
                lint_job:
                  script: 'echo lint_job'
                  rules:
                    - if: $var == null
                      needs: 
                        - job: rspec_job
                rspec_job:
                  script: 'echo rspec_job'
                  rules:
                    - if: $var == null
  1. When code pushed, the jobs should run in the following sequance: rspec_job -> lint_job -> main_job which indicates that the rule needs have taken precedence over needs set directly on the main_job

This MR enables below keywords under rule needs: job, artifacts, optional

    main_job:
      script: 'echo job'
      needs: [rspec_job]
      rules:
        - if: $var == null
          needs: 
            - job: lint_job
              artifacts: false
              optional: true

With FF disabled:

  1. In rails console disable the feature flag fully or per project
    Feature.disable(:introduce_rules_with_needs, project)
  2. Checkout my branch
  3. Create a project with yml file eg
                 main_job:
                  script: 'echo job'
                  needs: [rspec_job]
                  rules:
                    - if: $var == null
                      needs: [lint_job, rspec_job]
                lint_job:
                  script: 'echo lint_job'
                  rules:
                    - if: $var == null
                      needs: [rspec_job]
                rspec_job:
                  script: 'echo rspec_job'
                  rules:
                    - if: $var == null
  1. When code pushed, the jobs should run in the following sequence: rspec_job -> main_job -> lint_job which indicates that the job needs have taken precedence over rules needs.

QA

When a rule needs refer to a job in the later stage, an error is raised:
Screen_Shot_2023-03-28_at_14.06.11
When a rule needs refer to a job that doesn't exist, an error is raised:
Screen_Shot_2023-03-28_at_14.08.41
When a rule needs includes duplicate jobs
Screenshot_2023-05-09_at_12.10.43

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Kamil Trzciński (Back 2025-01-01)

Merge request reports