Hi Team ,
We have a new environment set up and we are trying to migrate old environment to the new Environment (data center migration) and the ask here is to get the list of all projects with a specific release version tag and get all the project names in the specific environment ,
any help would be appreciated to achieve this in a automated way as it is very critical .
My option which i am trying using power shell ******************************
$environmentName = “Q**”
- $projects = Octo.exe list-latestdeployments --environment $environmentName --APIkey $octopusAPIKey --server $octopusURL
what sub method to iterate this list projects and get the proper output ?
Hi @deepak.ponnada,
Thanks for getting in touch! Currently our CLI tool isn’t capable of this level of filtering. I think the best option would be to directly interface with the Octopus API. We have an open source repository with API script examples for a lot of different scenarios. I’ve linked to a script that should help get you started.
Let me know if this helps or if you have any further questions.
Best regards,
Daniel
Hi Daniel ,
Apparently the code which was shared is crashing out and not returning any value at line no 13 form the ps code , looks like the where clause is not getting satisfied here .
----- for reference -----
PS Script form code ***************************************
$environmentToUse = $dashboardInformation.Environments | Where-Object {$_.Name -eq $environmentName}
write-Host "environmentToUse " $environmentToUse
$deploymentsToEnvironment = @($dashboardInformation.Items | Where-Object {$_.EnvironmentId -eq $environmentToUse.Id})
write-Host "deploy to env " $deploymentsToEnvironment
PS Output : environmentToUse @{Id=Environments-362; Name=QF**; Links=}
" deploy to env " - This value is returning empty
Hi @deepak,
Thanks for getting back. I’ve just tested the script against my instance without any modifications and it worked without issue. The where-object for this line should work fine, unless the octopus dashboard doesn’t have any active deployments to that environment.
The Invoke-RestMethod in this script is referencing the dashboard endpoint, using it to confirm the Environments-ID based on the environment name you input at the top. Then checking the individual items on that dashboard for any deployments currently on the dashboard and matching that ID. Any values found are then added to the $deploymentsToEnvironment
variable, which is iterated over in the foreach to get the specific details.
I’d confirm that you’re referencing the correct space and that you can see deployments to the environment from the dashboard when logged in to Octopus.
Let me know how you go here.
Best regards,
Daniel