how to update octopus library variable set using powershell
Thanks for getting in touch!
The easiest way to interact with the API using Powershell is to use the octopus.client.
To help get you started, we have a repository of useful scripts located here: https://github.com/OctopusDeploy/OctopusDeploy-Api/tree/master/Octopus.Client/PowerShell
There may not be the exact one for your purpose there, but they will help provide the first steps.
I hope this helps. If you run into any problems with your script please let me know.
Thanks for your prompt response on this, really appreciate it!!
I am working on a project and trying to automate few task where in it involves updating the existing Library variable set. Though I went with the link which you provided it helped me to a level where I can get the values of the existing Library variable set but when I am trying to update the values of the corresponding variables it is giving issue unable to update the variable. It would be really great if you can show me a path to go forward as it been 2 days I am stuck in the same place despite of trying multiple things.
I request you to help me with any document or link which will give me some idea on how to update the values of the existing Library variable set. I know it maybe not the right ask but I am hoping to get a positive response from you as last time.
Looking forward to hearing from you.
Thanks & Regards,
I’ve spent sometime looking at this and the following script will retrieve a variable set, and allow you to change the value of a variable based on the variable name.
# You can this dll from your Octopus Server/Tentacle installation directory or from
Add-Type -Path 'C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll'
$apikey = 'API-XJF3OZREHTNRYTCI0BBUHI9N8S' # Get this from your profile
$octopusURI = 'http://localhost' # Your server address
$libraryVariableSetId = "LibraryVariableSets-1" # Get this from /api/libraryvariablesets
$variableName = "Variable name" # Name of the current variable
$variableValue = "Test" # New value for the variable
$endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$libraryVariableSet = $repository.LibraryVariableSets.Get($libraryVariableSetId);
$variables = $repository.VariableSets.Get($libraryVariableSet.VariableSetId);
It is fairly basic at this point so has a flaw where if there are multiple values attached to a variable, it will update all of them to the same value. If you need to modify this kind of variable then you will need to specifically select the one you want to modify prior to the AddOrUpdateVariableValue command.
I hope this helps.
I am able to update single library variable but how to update multiple library variables using variable set id can you please help me with any document or link which will give me some idea.
Thanks & Regards,
If you can update a single variable, then can you not just iterate that to update whichever ones you need to and then modify the entire set at the end?
The documentation available is everything I’ve already linked to.
We have the API wiki: https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki
And the GitHub resources already mentioned, plus you can view the workings of the octopus.client here: https://github.com/OctopusDeploy/OctopusClients
We just don’t have a guide on how to achieve the specific scenario that you’re aiming for, all I can really offer is what I have so far.
If you have a script example that you want us to look at we can try that, but we can’t write it for you.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.