I am writing a local powershell script and would like to be able to mass update variables across Octopus projects based on information I have in another system. I have absolutely no issues with obtaining the needed data from my other system; however, am slightly confused on how I should format the data for Ocotpus so that I could do a post command via powershell.
I reconginze too that the data that I need to post should be a json object. What kind of object though should I be using ahead of time to format my data into so that I can convert it to json? I have tried using a dictionary object; however, my issue there is I can have more than one key named the same thing. So I may have two environment names, representing two variables in octopus but will be scoped differently ultimately in octopus.
Also does the post made into octopus need to be one big bang post or can I submit small chunks of data at one time? How does this process work with the Rest API?
Thanks for getting in touch! There is a blog post that describes how to use PowerShell and talk to our Rest API: http://www.lavinski.me/calling-a-rest-json-api-with-powershell/
And then our API documentation can be found here: https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki
Hopefully that helps guide you on the right path!
Thanks for those documents. They are what I have been using up to this point to try to understand how to post objects to the server and have been largely unsuccessful.
The challange I have this with document, http://www.lavinski.me/calling-a-rest-json-api-with-powershell/, is that he is using a hashtable. In my hastable, I have multiple keys that could be the same name; however, they have a different environment associated with them. For example, Environment1 may have the value of Staging then Environment1 may have the value of System. These two environments have the same name but two different values. With hashtables or dictionary objects, keys cannot have the same name. I have attempted to to created a dictionary object, assign one set of variables (Name=Enviornment1 and Value =Staging), post that to the server, clear my object, then set Name=Environment2 with a different value but get a bad request message everytime I try that.
There is also an add method on the variable set object that comes back from the server after calling the get command that looks something like OctopusVariableset.Varaibles.Add(). The add method takes 1 parameter. If I try to assign a value to it, I am given a message saying the collection has a fixed size.
The thought being that I could convert the variable set from json once the get command runs then convert it back to json after the command runs in order to post it back to the sever. That doesn’t work either due to a bad request.
What am I missing?
One other brief thing I have tried also since an OctopusVariableSet.Variable is a array of dictionary objects is to try to use the insert command inserting the index of the array plus my dictionary object that contains both a name and value; however, the collection is supposed to be a fixed size. Is that because there more values in a variable than just a name and size? Do I need to generate all those values somehow?
This blog post shows how to play around with variables using the AP
I’m pretty sure it’ll help you do what you are trying to do