YAML to JSON to string and output variable max length

Hi,

I have a large configuration file in YAML format which is stored in source control (Git). I want to make all of the key-value pairs within the YAML file available to all steps within a deployment. I don’t want to store my configuration in variables in Octopus permanently since I need that same configuration elsewhere in our deployment pipeline. I want to have a single source of truth.

Using PowerShell I’m looking to import the YAML file using PowerYAML, convert the resulting hash table to a JSON object, and then convert this to a string. I can then pass that string to Octopus as an output variable. Any steps requiring a configuration parameter could read the variable and translate it back from a string to JSON again where I can easily find and access the key/value pairs.

Is there a max length restriction on output variables which could limit this approach or a better way out there to access YAML or JSON as a variable at deployment time (not a string).

Many thanks,
Blair.

I’ve just seen the Octostache Json Formatting post at https://octopus.com/blog/octostache-json-formatting so will try to use that first.

Many thanks,
Blair.

Hi Blair,

Hopefully it works out to be perfect timing! Keep in touch and let us know how you get on. :slight_smile:

Happy Deployments!
Mike

Hi Mike,

I’m pleased to report that I have a solution which works. I don’t appear to have hit a limitation on the output variable length yet. Unfortunately I wasn’t able to use the recent Octostache improvements due to the way PowerShell converts to JSON. My solution is:

  1. I obtain a YAML configuration file from Git which contains all configuration (key/value pairs) required for a deployment. This YAML file is read in as a hash table within a PowerShell deployment script step.

  2. Using the PowerShell ConvertTo-JSON cmdlet, I convert the hash table to a single JSON formatted string and then pass this to an Octopus output variable.

  3. In subsequent deployment scripts I can read the output variable back in use the ConvertFrom-JSON cmdlet. I can then access all my key/value items with a simple hash table key/value reference.

Cheers,
Blair.

Hi Blair,

Thanks for getting back to me. I have heard of some quirks with PowerShell’s conversion to JSON related to how deep it traverses the graph. You could try setting the -Depth argument to make it traverse deeper, or using the -Compress flag to omit formatting in the resulting string.

Either way it sounds like you’re really getting your hands dirty and making headway! :slight_smile:

Keep in touch!
Mike