firecow / gitlab-ci-local

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

Rules problem with double quotes #1224

Closed bcouetil closed 1 month ago

bcouetil commented 1 month ago

Hello, long time no see, thank you for the great work 🤗

I encounter a rule problem using quotes. example is simple, I could remove the quote for it, but in real life I need them to have a longer string, for example "$CI_DEFAULT_BRANCH-test".

Minimal .gitlab-ci.yml illustrating the issue

repro-ok:
  script: echo "working"
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

repro-ko:
  script: echo "NOT working"
  rules:
    - if: $CI_COMMIT_BRANCH == "$CI_DEFAULT_BRANCH"

# SyntaxError: Unexpected identifier 'develop'
#     at Function.evaluateRuleIf (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:223:29)
#     at Function.getRulesResult (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:185:23)
#     at new Job (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/job.ts:189:38)
#     at /opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:160:29
#     at Function.forEachRealJob (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:53:13)
#     at Parser.init (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:148:15)
#     at Function.create (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:59:9)
#     at handler (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/handler.ts:58:18)
#     at Object.handler (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/index.ts:36:21)

repro-ko-2:
  script: echo "also NOT working"
  rules:
    - if: $CI_DEFAULT_BRANCH == "$CI_COMMIT_BRANCH"
#
# SyntaxError: Unexpected number
#     at Function.evaluateRuleIf (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:223:29)
#     at Function.getRulesResult (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:185:23)
#     at new Job (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/job.ts:189:38)
#     at /opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:160:29
#     at Function.forEachRealJob (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:53:13)
#     at Parser.init (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:148:15)
#     at Function.create (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:59:9)
#     at handler (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/handler.ts:58:18)
#     at Object.handler (/opt/homebrew/Cellar/gitlab-ci-local/4.49.0/libexec/lib/node_modules/gitlab-ci-local/src/index.ts:36:21)

Expected behavior

No error

Host information

MacOS gitlab-ci-local 4.49.0

Containerd binary

Orbstack

ANGkeith commented 1 month ago

problem can be replicated but I have a side question

but in real life I need them to have a longer string, for example "$CI_DEFAULT_BRANCH-test".

do you have a concrete example that works in the gitlab-ci ?

I tried the following but it didnt work

# CI_COMMIT_BRANCH=main2
# CI_DEFAULT_BRANCH=main
---
alpine:
  rules:
    # - if: $CI_COMMIT_BRANCH == "main2"                    # triggers pipeline
    - if: $CI_COMMIT_BRANCH == "${CI_DEFAULT_BRANCH}2"      # does not trigger pipeline
  image: alpine
  script:
    - echo "Job should run"
bcouetil commented 1 month ago

You are right, sorry, my full use case worked on GitLab CI but for another reason !

Thank you for your time.

Closing.