0

Very confused on why this job is added to the pipeline, despite the condition being not satisfied:

rules:
  - if: $COMMIT_HASH != "$CI_COMMIT_SHORT_SHA"

The $COMMIT_HASH takes the default value of $CI_COMMIT_SHORT_SHA and when I troubleshot this on the script, I found that that they are indeed identical:

echo "COMMIT_HASH is $COMMIT_HASH and CI_COMMIT_SHORT_SHA is $CI_COMMIT_SHORT_SHA"

and I got:

COMMIT_HASH is 60a1ee54 and CI_COMMIT_SHORT_SHA is 60a1ee54

I feel like this is a double quote thing or something. Any help please ?

joe1531
  • 345
  • 4
  • 16
  • 1
    Why quote `"$CI_COMMIT_SHORT_SHA"` but not `$COMMIT_HASH`? I know nothing of Gitlab CI, but I'd guess you should either quote both or neither. – Joachim Sauer Mar 14 '23 at 11:46
  • I ended up doing this because of VS Code marking it as invalid when I quote both and it goes like this: Unexpected tag at node endYAML Unexpected double-quoted-scalar at node end – joe1531 Mar 14 '23 at 11:46
  • Ugh, Yaml is just a a dream like that. Way too much flexibility that's not obvious ... still: try not quoting either one. – Joachim Sauer Mar 14 '23 at 11:48
  • `COMMIT_HASH` is not a builtin variable. Where/how are you defining this variable? It's possible you're defining this variable in a place or manner that is not supported for `rules:` evaluation. – sytech Mar 15 '23 at 01:09

1 Answers1

0

Perhaps flip your logic. c.f. here for a variety of possible approaches.

Also, try single-quoting your entire condition.

workflow:
  rules:
    - if: '"$COMMIT_HASH" == "$CI_COMMIT_SHORT_SHA"'
      when: never
    - when: always
Paul Hodges
  • 13,382
  • 1
  • 17
  • 36