Bash variable does not work

ruf-r
(Gilles) #1

Hi, I should be missing the obvious: that’s the first time I use a bash script to deploy to CentOS.
I’m trying to perform the following commands:

newReleaseFolder = $(get_octopusvariable "Octopus.Action[Deploy package].Package.InstallationDirectoryPath")
echo "$newReleaseFolder"

pwd

releaseNumber = $(get_octopusvariable "Octopus.Release.Number")
echo "$releaseNumber"

environment = $(get_octopusvariable "Octopus.Environment.Name")
echo "$environment"

echo "FINISHED !"

But the steps to get the variable do not work.

/home/extend/.octopus/OctopusServer/Work/20190612170824-28270-697/Script.sh: line 4: newReleaseFolder: command not found


/home/extend/.octopus/OctopusServer/Work/20190612170824-28270-697


/home/extend/.octopus/OctopusServer/Work/20190612170824-28270-697/Script.sh: line 9: releaseNumber: command not found


/home/extend/.octopus/OctopusServer/Work/20190612170824-28270-697/Script.sh: line 12: environment: command not found

FINISHED  !

I’m using Octopus v2019.5.7
What is the correct way to use variables in a bash inline script?
Regards

(Rob Pearson) #3

Hi Gilles,

Thanks for getting in touch. I didn’t have a CentOS box available but I tested the following against an Ubuntu box. I had troubles with this as well as I’m not a bash scripting expert. I read the following on this site.

This is one of those areas where formatting is important. Note there is no space on either side of the equals ( = ) sign. We also leave off the $ sign from the beginning of the variable name when setting it.

So in your example, we need to remove the spaces when assigning variables. I noticed our docs site has the incorrect formatting so I’ll update it as well. :slight_smile:

This is the example that I got working:

echo "Running bash script"

releaseNumber=$(get_octopusvariable "Octopus.Release.Number")
echo “Release Number: $releaseNumber"

environment=$(get_octopusvariable "Octopus.Environment.Name")
echo "Environment: $environment"

Hope this helps.

Thanks

Rob

1 Like
(Gilles) #4

That was the problem, thanks for your help.

1 Like
(system) closed #5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.