Skip to content

Instantly share code, notes, and snippets.

@dennisroche
Created April 5, 2018 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennisroche/74ce317a33d9d521d5132b937f1f0125 to your computer and use it in GitHub Desktop.
Save dennisroche/74ce317a33d9d521d5132b937f1f0125 to your computer and use it in GitHub Desktop.
Octopus Deploy script to shift a range of projects to the right (dev to staging) as a set
$octo = Get-OctopusTools
Write-Heading 'Projects'
function GetProjectsInGroup([string]$projectGroupName, [string]$ignoreProjectNames) {
$projectGroup = Invoke-OctopusApi '/api/projectgroups/all' | Where-Object { $_.Name -eq $projectGroupName }
if ($null -eq $projectGroup) {
Write-Fatal "Project $projectGroupName not found"
}
Write-Host "Project Group: $($projectGroup.Name)"
Write-Verbose "`t$($this.BaseUrl)$($projectGroup.Links.Self)"
$comparisonArray = $ignoreProjectNames.Split("`n") | % Trim
Write-Host "Skipping: $comparisonArray"
$projects = Invoke-OctopusApi "/api/projects/all" | Where-Object { $_.ProjectGroupId -eq $projectGroup.Id -and $_.Name -notin $comparisonArray }
$projects | ForEach-Object {
Write-Host "- $($_.Name)"
}
$projects | Write-Output
}
$projects = GetProjectsInGroup $ProjectGroupName $IgnoreProjects
$projects | ForEach-Object {
# Release Promotion
# https://octopus.com/docs/api-and-integration/octo.exe-command-line/promoting-releases
$projectName = $_.Name
Write-Heading "$projectName"
Write-Host "Promoting '$projectName' from $PromoteFrom to $PromoteTo"
& $octo promote-release --project=$projectName --from=$PromoteFrom --to=$PromoteTo --tenant=* --server=$OctopusUrl --apiKey=$OctopusApiKey --updateVariables
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment