Hi team,
I am looking for octopus rest api which will give me list of projects in particular environment. supose i am having environment-A and Environment-B. and both the environment having multiple projects so i want to fetch the list of project which are the part of Environment-A. so can you please help me on this to get the octopus Rest API ?
Thanks
shubham
Hi Shubham,
Thanks for getting in touch!
Having looked at the Rest API, the simplest way to achieve this would be to use the Octopus Client:
While we don’t have a script to achieve what you are after, I will include some examples which you could tailor to suit your needs:
# You can this dll from your Octopus Server/Tentacle installation directory or from
# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path 'Octopus.Client.dll'
$apikey = 'API-xxx' # Get this from your profile
$octopusURI = 'http://octopus' # Your server address
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$machineIds = $OctopusParameters['Octopus.Deployment.Machines'].Split(',')
foreach ($machineId in $machineIds) {
$machine = $repository.Machines.Get($machineId)
Write-Host $machine.Name
}
# You can this dll from your Octopus Server/Tentacle installation directory or from
# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path 'Octopus.Client.dll'
$octopusURL = 'http://youroctopusserver' # Your Octopus Server address
$apikey = 'API-xxxxx' # Get this from your profile
$projectName = 'ChildProject' # The name of the project that you want to create a deployment for
$environmentName = 'Development' # The environment you want to deploy to
$spaceName = "Default" # The space that the $projectName is in
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL,$apikey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$Header = @{ "X-Octopus-ApiKey" = $apiKey }
# Getting space
$spaces = (Invoke-WebRequest "$OctopusURL/api/spaces?skip=0" -Method Get -Headers $header -UseBasicParsing).content | ConvertFrom-Json
$spaceId = ($spaces.Items | Where-Object{($_.Name -eq $spaceName)}).Id
This file has been truncated. show original
If you require any further assistance, please do reach out.
Kind regards,
Ziaul
system
(system)
Closed
29 July 2020 21:02
5
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.