Issue
I have created a jenkinsfile in which I need to go into an already created directory. But the problem is that the name of the directory can be variable, eg: dir ('RELEASE/abc/${abc-version}')
. The abc-version
is passed as a string argument in the pipeline.
The problem is that, on running the pipeline, jenkins creates a directory named as "${abc-version}
" rather than passing it as an argument.
I have failed in doing so till now. Is this even possible? Can we pass a variable in the dir step?
EDIT: I tried with %abc-version% and it still doesn't work. It instead creates a directory with %abc-version% rather than taking it as a variable.
Also, my parameter is like: abc-version
. Has it anyting to do with the problem?
Solution
Use double quotes
dir ("RELEASE/abc/${abc_version}")
in groovy Single quotes are a standard Java String while Double quotes are a templatable String
e.g
a = 10
b = "RELEASE/abc/${a}"
c = 'RELEASE/abc/${a}'
print(b)
print('\n')
print(c)
output will be
RELEASE/abc/10
RELEASE/abc/${a}
You can try it here
Answered By - Talha Junaid
Answer Checked By - Gilberto Lyons (JavaFixing Admin)