Reference files within a package with Bash

The documentation clearly explains how to reference files within a package with PowerShell, but since scripts in Octopus Deploy can be written in C#, Bash and F# as well, it would be neat if examples for these other languages were also provided.

I would like to know how I can reference files within a package with Bash. Can you please help me with some examples, or even better — update the documentation with some Bash examples?

Ok, I found the output variables documentation which has examples for all languages as well as some examples in the raw scripting tutorial. However, when I attempt to do the following in my script:

unzip -d /usr/share/nginx/html "#{Octopus.Action[Transfer].Output.Package.FilePath}"

I get the following error:

unzip: can't open #{Octopus.Action[Transfer].Output.Package.FilePath}[.zip]
The remote script failed with exit code 1

Why doesn’t the variable substitution work?

I’ve also tried to remove the OctopusUseRawScript variable to have Calamari run on the Deployment Target and changed my script to look like this:

path = $(get_octopusvariable "Octopus.Action[Transfer].Output.FilePath")
unzip -d /usr/share/nginx/html $path

But this fails with the following error:

/home/octopus/.octopus/OctopusServer/Work/20180312010836-264-87/script.sh: line 1: path: command not found
BusyBox v1.27.2 (2017-12-12 10:41:50 GMT) multi-call binary.
Usage unzip [-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]
Extract FILEs from ZIP archive
...
The remote script failed with exit code 1

I’ve tried to do echo "Path: $path" and it looks like $path is empty. Am I using get_octopusvariable wrong or can you notice anything else that’s broken?

Hi Asbjørn,

Thanks for getting in touch!

I will make a note of and update the docs to have the samples for referencing files within a package written for the other script options as well.

Now, I’m not sure why your first setup didn’t work.

I’ve tested the scenario on a local instance with the following setup (I have OctopusUseRawScript enabled for my project):

The Transfer step just uploads and copies the package to tmp/uploads once transferred.

The Extract step runs the following bash script:

rm -fr ~/tmp/extract
unzip -d ~/tmp/extract "#{Octopus.Action[Transfer].Output.Package.FilePath}"

And this works as I expect it to work.

There’s a syntax issue with the second setup you tried. path = $(get_octopusvariable "Octopus.Action[Transfer].Output.FilePath") should actually be path=$(get_octopusvariable "Octopus.Action[Transfer].Output.FilePath") (notice the lack of spaces around the = sign).

If you are still unable to get this to work, could you send through some screenshots of your project deployment process and what OS your target server is running. (My target server I tested with is running Ubuntu 16.04)

Thank you and best regards,
Henrik

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