0

In my gitlab-ci.yml, I'm trying to compare values inside of 2 files using bash string comparison.

build-jar:
  stage: build_jar
  image: alpine
  script:
    - cat version_cache/chart_version.txt
    - cat version_cache/app_version.txt

    # check to see if the versions match
    - [ "$(sed -En s/'(^.+)-SNAPSHOT'/'\1'/p ./version_cache/app_version.txt)" = $(< ./version_cache/chart_version.txt) ]

I keep getting this error:

(<unknown>): found unknown escape character while parsing a quoted scalar at line 75 column 9

paiego
  • 3,619
  • 34
  • 43
  • 1
    **TL;DR:** Replace `- [ …` with `- |` *newline* `[ …` – ErikMD Jan 25 '22 at 18:39
  • @ErikMD If I wanted to use this comparison in the "rules:" section of the job definition? This seem to only be available in the "script" section. – paiego Jan 25 '22 at 19:37
  • regarding your question whether it's feasible to migrate this test to the `rules:` field: syntactically speaking, no; but it also depends on how you compute the contents of the `*_version.txt` files: maybe the corresponding info can be put in a "variable", etc.; in any case, feel free to open a new question with a more comprehensive `.gitlab-ci.yml` snippet if you still have some doubts on this issue. – ErikMD Jan 25 '22 at 22:52

0 Answers0