gitlab-ci-local icon indicating copy to clipboard operation
gitlab-ci-local copied to clipboard

Support needs specified inside rules

Open compiaffe opened this issue 5 months ago • 1 comments

Minimal .gitlab-ci.yml illustrating the issue

variables:
  OVERRIDE_NEEDS_TO: "a"
build-a:
  stage: build
  script: echo "Feature branch, so building dev version..."

build-b:
  stage: build
  script: echo "Default branch, so building prod version..."

tests:
  stage: test
  needs:
    - job: build-a
      optional: true
    - job: build-b
      optional: true
  rules:
    - if: $OVERRIDE_NEEDS_TO == "a"
      needs: ['build-a']
    - if: $OVERRIDE_NEEDS_TO == "b"
      needs: ['build-b']
  script: echo "Running dev specs by default, or prod specs when default branch..."

Experienced output

❯ gitlab-ci-local --list
Using fallback git commit data
Unable to retrieve default remote branch, falling back to `main`. The default remote branch can be set via `git remote set-head origin <default_branch>`Using fallback git remote data
parsing and downloads finished in 51 ms.
json schema validated in 133 ms
name     description  stage   when        allow_failure  needs
build-a               build   on_success  false
build-b               build   on_success  false
tests                 test    on_success  false          [build-a,build-b]

Expected behavior

Tests to have a non-optional dependency on build-a only

Host information CachyOS gitlab-ci-local 4.60.0 Containerd binary No, running this directly

Additional context Add any other context about the problem here.

compiaffe avatar Jul 08 '25 11:07 compiaffe

Uh, that must be a new feature. I'm pretty sure we do not support needs in rules. So this is a feature request 👍

firecow avatar Jul 10 '25 09:07 firecow