firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.3k stars 129 forks source link

Allow usage of workflow:rules variables #691

Open peterbbeu opened 1 year ago

peterbbeu commented 1 year ago

Note: possibly related to #685, I hoped this would fix it, but it doesn't seem to have (I tried by building latest from master)

Minimal .gitlab-ci.yml illustrating the issue I made a minimal test case here, but I'll replicate it below: https://github.com/peterbbeu/gitlab-ci-local-testcase/tree/3926892

The output of gitlab-ci-local can be seen here: https://github.com/peterbbeu/gitlab-ci-local-testcase/actions/runs/3685068421/jobs/6235567395

.gitlab-ci.yml

workflow:
  rules:
    - if: $CI_COMMIT_TAG
      variables:
        IS_TAG_BUILD: 1
    - if: $CI_COMMIT_TAG == null
      variables:
        IS_TAG_BUILD: 0

hello-world:
  stage: build
  script:
    - echo IS_TAG_BUILD - $IS_TAG_BUILD

Expected behavior See these two pipelines: Branch: https://gitlab.com/petervv/gitlab-ci-test/-/jobs/3465834365 Tag: https://gitlab.com/petervv/gitlab-ci-test/-/jobs/3465838409

I expect $IS_TAG_BUILD to be either 0 or 1 like on gitlab itself. In gitlab-ci-local currently it's unset, like this:

hello-world starting shell (build)
hello-world > $ echo IS_TAG_BUILD - $IS_TAG_BUILD
hello-world > IS_TAG_BUILD -
hello-world finished in 21 ms

Host information Ubuntu 22.04 gitlab-ci-local 4.36.1 (latest build from git)

Additional context See also #685 (?)

firecow commented 1 year ago

Rename this issue to "workflow rules variables".

I'll add the label "feature request", it's not related to #685 in any way.

You just stumpled upon a missing feature.

peterbbeu commented 1 year ago

Rename this issue to "workflow rules variables".

I have done so, thank you. It felt kind of similar, but I guess not ;)

node13h commented 8 months ago

This one would be really nice to have. My use case:

workflow:
  rules:
    ...
    - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/
      variables:
        IS_TAGGED_RELEASE: "true"

publish:
  rules:
    - if: $IS_TAGGED_RELEASE

Thank you for the fantastic tool!