Inject Library Variable Set into Deploy Raw YAML step

I have a Library Variable Set named “Properties Vars” that I’m trying to inject into a yaml file in a Deploy Raw YAML step in this format

apiVersion: v1
kind: ConfigMap
metadata:
  name: properties-#{Octopus.Environment.Name}
  namespace: #{Octopus.Environment.Name}
data:
  application.properties: |-
    #{each p in <some way to access the library set>}
    #{p.Name}=#{p.Value}
    #{/each}

Is there a way to do that?

Hi @jmccormick,

Thanks for getting in touch! Great question, though I think the closest option would be to do something like what is mentioned in this doc section. To summarize, if the variable value in your variable set is defined like {Cat: {Price: 11.5, Description: "Meow"}, Dog: {Price: 17.5, Description: "Woof"}}, you could iterate over each item with:

#{each item in MyObjects}
	#{item.Key}: #{item.Value.Price}
#{/each} 

My guess is this isn’t exactly what you’re after, however, as I imagine you’re wanting to iterate over many variables in the set - is that correct? Perhaps the solution worked out in this thread may be helpful in getting you closer to what you’re looking to achieve.

I hope this helps, and please let me know if you have any follow up questions or concerns. :slight_smile:

Best regards,

Kenny

Thanks @Kenneth_Bates

That’s helpful to know that I can iterate over the keys in “MyObject” that way. I’m actually currently implementing the method in this thread for another set of variables where we have our variables named with a common prepended string – referencing them with $OctopusParameters.Keys | where {$_ -like "env.*"} in a ps1 pre-deploy script then outputting those as an array of variables I can iterate over in the yaml with #{each}. But, more specifically, how do I reference the Library Variable Set itself? Is there something I can replace MyObject with in my yaml to reference the Library Set directly in the manifest, or how do I reference the Library Set in a ps1 pre-deploy script to populate MyObject with only the variables from the “Properties Vars” set?

Thanks again!

Hi @jmccormick,

Thanks for following up, and anytime! To make sure I understand, are you wanting to essentially ignore project variables here? To do this you may need to go the API route to grab only the variables in a set. Perhaps this sample script could help get you closer to what you’re looking to achieve.

Otherwise you may be able to achieve this by implementing some sort of variable set-specific prepending convention similar to how I understand you’re doing with the other set of variables.

I hope that helps!

Best regards,

Kenny