0

My build failed when I had a hyphen in a variable name but succeeded when I changed it to an underscore.

The error was this but I could see in the online Workspace browser that it was valid and as mentioned above it succeeded with an underscore!

15:55:25 + MY-DISTRO=/home/jenkins/workspace/build-prod/my-distro
15:55:25 /tmp/hudson6751264218812911564.sh: line 3: MY-DISTRO=/home/jenkins/workspace/build-prod/my-distro: No such file or directory

What are valid characters for Jenkins variables names and where is this documented?

opticyclic
  • 7,412
  • 12
  • 81
  • 155

3 Answers3

1

Judging by the .sh extension of the temporary script in the log you pasted, I assume you used the Execute shell build step in Jenkins - so in this case "valid" variable names mean variables in a linux shell script (the exact shell type might vary based on local configuration) - see for example this thread about allowed names on linux.

In case you have a windows slave, and use the Execute Windows batch command build step, you would of course have to check rules for windows variable names.

Also note that variables used in other places as these and similar build steps could potentially follow completely different rules (though sometimes they overlap). For example: if a plugin uses the Token Macro Plugin for evaluating expressions, you would have to refer to environmental variables with ${ENV,var="VARIABLENAME"}.

Community
  • 1
  • 1
Akos Bannerth
  • 1,964
  • 18
  • 14
0

Jenkins is java based. Most probably it accepts java variable convention. I suggest avoid using $ in variable names since unix based operating systems treat it differently.

Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
0

What Atilla said, but avoid dots (.) as well.

Slav
  • 27,057
  • 11
  • 80
  • 104