-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_runbook.ps1
27 lines (22 loc) · 1.05 KB
/
run_runbook.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ErrorActionPreference = "Stop";
# Define working variables
$octopusURL = Get-AutomationVariable -Name 'octoURL'
$octopusAPIKey = Get-AutomationVariable -Name 'apiKey'
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$spaceName = Get-AutomationVariable -Name 'octoSpace'
$projectName = Get-AutomationVariable -Name 'octoProject'
$runbookName = Get-AutomationVariable -Name 'octoRunbook'
$environmentNames = @(Get-AutomationVariable -Name 'envName')
# Get space
$space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName}
Write-Host "Using Space named $($space.Name) with id $($space.Id)"
# Create the release body
$createRunbookRunCommandV1 = @{
SpaceId = $space.Id
SpaceIdOrName = $spaceName
ProjectName = $projectName
RunbookName = $runbookName
EnvironmentNames = $environmentNames
} | ConvertTo-Json
# Run runbook
Invoke-RestMethod -Method POST -Uri "$OctopusURL/api/$($Space.Id)/runbook-runs/create/v1" -Body $createRunbookRunCommandV1 -Headers $header