1

I have the usual section

variables:
  DESTINATION: "dev" 
  dev-SERVERNUMBERS: "0 1"

And, this had been working all long and suddenly. Gitlab CI is complaining and giving the following error message

/bin/bash: line 103: export: `dev-SERVERNUMBERS=0 1': not a valid identifier

Initially, I thought I was exporting something wrong. But, it looks like that is how gitlab runners work they export your variables to make them available to all jobs within your pipeline. I have NO export statement within any before_script.

I can understand why it is complaining because it expects the variable to have double quotes around it in order to export. But, it DID NOT complain now for atleast 2 months, so I cannot understand why now ?

I find gitlab-ci just so unpredictable and extremely frustrating to use. By now, if I had automated this build of mine via shell scripts I would have be on my way. And, I have been stuck on this error for 3 days now. It does not even print out any debug echos that I have set up and straight away gives this line number which has nothing to do with my .gitlab-ci.yaml At the very least it should give the verbose command that is trying to execute.

user1561783
  • 483
  • 1
  • 4
  • 14

1 Answers1

2

Bash is complaining about the environment variable name (the identifier) not necessarily the value. - is not an allowed character in environment variable names. You can only use alphanumerics (a-Z, 0-9), and underscores (_).

This is a limitation of bash, not GitLab CI.

export foo="0 1"  # OK
export foo-bar="0 1"  # Not OK
bash: export: `foo-bar=0 1': not a valid identifier
sytech
  • 29,298
  • 3
  • 45
  • 86
  • Thank You @sytech that might be it. Oddly, Gitlab-CI did not flag this an error. But, that could have been because Gitlab-CI does run an internal lint on Gitlab-CI yaml scripts and I have only started using this variable 3 days back. Let me try this first. Thanks again – user1561783 May 19 '22 at 21:42
  • 1
    Glad that was helpful. GitLab probably doesn't flag this as an error because `-` and other characters may be allowed in other environments ([like Windows](https://stackoverflow.com/a/20635858/5747944)). GitLab doesn't know your runner shell environment ahead of time, so this may help explain that behavior @user1561783 – sytech May 19 '22 at 21:46