swalford
(Shane Walford)
30 May 2019 09:24
1
Hi
Can you connect to Octopus from PowerShell remotely, to add variables that are scoped?
Thanks
Shane
Hi Shane,
Yes, as with all things in Octopus, you can add scoped variables from the API using PowerShell. In fact, we have an example of adding Environment-scoped variables in our Api Examples repo here:
$baseUri = "http://output.url" # the address of your octopus server
$apiKey = "API-APIKEYAPIKEYAPIKEY" # an api-key from an account with permissions to create
# variables on the environment you specify
$projectName = "Project Name" # If you don't know your project Id add your project name here
# and the script will print out your project Id on the first run,
# then you can add it below
$projectId = "" # set this if you know it, the script will run faster if it has
# a projectId, otherwise it will look up the project using its name
$environment = "Production" # the name of the environment you want to scope the variables to
$variablesToAdd = "First", "Second", "Third" #all the variables you want to createe
function Get-OctopusResource([string]$uri) {
Write-Host "[GET]: $uri"
return Invoke-RestMethod -Method Get -Uri "$baseUri/$uri" -Headers $headers
}
This file has been truncated. show original
I hope this is a helpful example. Feel free to reach out if you need any further help with the script.
Thanks and Happy Deployments!
Jason
system
(system)
Closed
30 June 2019 00:22
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.