-
-
Save antonydenyer/4628d631e5a88aba5091 to your computer and use it in GitHub Desktop.
Promote release from staging to other environments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$api = "http://octopus.dev.azure.fundapps.co/" | |
$url = $api + "/api/projects/projects-1/most-recent-deployment/" | |
$response = Invoke-RestMethod -Uri $url -Method GET -Headers @{"X-Octopus-ApiKey"="x"} | |
$latestMaster = $response | where {$_.Name -eq "Deploy to Staging (master)"} | |
$url = $api + "/api/environments" | |
$stagingEnvironments = Invoke-RestMethod -Uri $url -Method GET -Headers @{"X-Octopus-ApiKey"="x"} | |
$stagingEnvironments = $stagingEnvironments | where {$_.Name.StartsWith("Staging ")} | where {$_.Name -ne "Staging (master)"} | where {$_.Name -ne "Staging (develop)"} | |
foreach ($environment in $stagingEnvironments) { | |
$command = '{"ReleaseId":"' + $latestMaster.ReleaseId + '" ,"EnvironmentId":"' + $environment.Id + '"}' | |
$url = $api + "/api/projects/projects-1/releases/" + $latestMaster.ReleaseId + "/deployments" | |
$response = Invoke-RestMethod -Uri $url -ContentType "application/json" -Method POST -Headers @{"X-Octopus-ApiKey"="x"} -Body $command | |
$url = $api + $response.Links.Task | |
$taskStatus = Invoke-RestMethod -Uri $url -Method GET -Headers @{"X-Octopus-ApiKey"="x"} | |
Write-Host "Deploying" $latestMaster.ReleaseId "to" $environment.Name "-" $environment.Id " " -nonewline; | |
do | |
{ | |
$taskStatus = Invoke-RestMethod -Uri $url -Method GET -Headers @{"X-Octopus-ApiKey"="x"} | |
Write-Host "." -nonewline; | |
sleep 1 | |
if($taskStatus.State -eq "Failed") | |
{ | |
write-output "Deploy Failed" $taskStatus.ErrorMessage $taskStatus.Links.Web | |
exit 1 | |
} | |
} | |
while($taskStatus.State -ne "Success") | |
Write-Host "." | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment