Hello guys,
I’m trying to sort out how to list projects which have releases on specific environment and on specific target role.
Example: Get a list of all projects which are deployed on STAGE and on the target machine with role WebserverExternal.
Add-Type -Path 'Octopus.Client.dll'
$apikey = 'API-*********'
$octopusURI = 'http://octopusserver.domain.com'
$environment = "STAGE"
$role = "WebserverExternal"
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$project = $repository.Projects.FindByName($projectName)
$process = $repository.DeploymentProcesses.Get($project.DeploymentProcessId)
$environmentToAdd = $repository.Environments.FindByName($environment)
$webClient = New-Object System.Net.WebClient
$webClient.Headers.add('accept','application/json')
$webClient.Headers.add('X-Octopus-ApiKey',$apikey)
$webClient.Headers.add('X-NuGet-ApiKey',$apikey)
$allRoles = $webClient.DownloadString($octopusURI+'/api/machineroles/all?ApiKey='+$apikey)
Any help will be much appreciated.
Kind Regards,
B