Inconsistent json snippet variable output Powershell and Bash

Hi everyone,

I am evaluating Octopus deploy for improving our DevOps and continuous delivery practices. We have.Net framework applications that run on Windows hosts, and .Net core applications that run on Linux.

I have created a single project to tinker with, with a Windows tentacle (Windows 10) and an SSH tentacle to Ubuntu desktop. The SSH tentacle uses the option “Mono not installed”.

Now I created a simple JSON snippet variable (called “Configuration.Json”) and attempted to use that snippet in both Powershell and Bash scripts. In Bash, I tried to reference the variable from a script defined in Octopus, and from an external Bash script in the package. All three should, in theory, have the same output, but it’s all different.

Step 3 in the screenshot: The Powershell output is correct, the entire string as defined in the variable is printed. The script is simply:

Write-Host $OctopusParameters['Configuration.Json']

Step 4 in the screenshot: The Bash script from source has the entire string, but the quotes are gone making the JSON invalid. The script looks like:

echo "#{Configuration.Json}"

Step 5 in the screenshot: The external Bash script has both the quotes and part of the string missing. The script looks like this:

echo "$1" 

The following argument is passed to the script: “#{Configuration.Json}”

Can someone help me achieve more consistent behavior? Thanks in advance for the help!

Kind regards,
Oskar uit de Bos

Hi Oskar,

Thank you for getting in touch. Apologies for the delay getting back to you.

In bash, when you echo "#{Configuration.Json}" you are essentially doing: echo "{ "name": "John", "age": 31, "city": "New York" }". Try the latter and you will see that it returns the same result that you are seeing because the inner quotes are being interpreted. You need to use strong quoting (single quotes) so the contents of the string are not interpreted: echo '#{Configuration.Json}'.

I hope this helps.

Cheers,
Shane

Hi Shane,

No need to apologize, it was the weekend after all! Your suggestion solved my problem right away. Feel a bit silly that I didn’t figure that out by myself after some trial&error. Let’s chalk it up to the weekend :slight_smile:

Thanks for the help!

Regards,
Oskar uit de Bos