Programmatically saving a variable to a variable set

I am using Octopus to create some Azure resources, and I’m a little bit stuck on variables. One example use case is that I am creating a Service Bus resource, and then I am creating a Web App to check on the Service Bus queue and act on messages with the queue. I know that I can use output variables to shuttle values around from step to step within the same project. However, I sometimes need to get the keys for my Service Bus queue and hand them to a Web App I’m creating in another project altogether. I know how to extract the Service Bus key at creation, but is there a way to save that to a variable set so that it is available to steps in other projects? Currently, I am manually getting the Service Bus keys manually and pasting them into my variable sets, but obviously, this does not scale well. Any guidance would be appreciated.

Hi,

Thanks for reaching out. From what you say about that scenario, I believe that putting the variables in a variable set might not scale that well either.

What I would do is, at the begining of you WebApp creation on another project, have a Powershell Script step that fetches the info you need from your Service Bus, and then creates an output variable which you’ll feed to your WebApp. This way you’ll always be getting the latest info from your ServiceBus when you create your webapp, instead of relying on the value that was injected once on a Variable Set.

Let me know if that makes sense for your scenario.

Cheers!
Dalmiro

Actually, that makes a lot of sense, Dalmiro. I’m going to try this out and see how it goes. Thanks for the suggestion.

Just out of curiosity, is there a way to take the output of a step and put it into a variable set for future use, should the need to do it this way arise?

Something like this might help: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/Octopus.Client/PowerShell/Variables/AddVariableToLibraryVariableSet.ps1

Awesome. We will definitely give that a look. Thanks for all the good info!

Notice:

This issue has been closed due to inactivity. If you encounter the same or a similar issue and require help, please open a new discussion (if we asked for logs or extra details in this thread, consider including them in the new thread). If you are the creator of this thread and believe it should not be closed let us know via our support email.