Last active
February 3, 2021 13:11
-
-
Save Alex-Yates/656f6ec59051787e44e6c12a7109b8cd to your computer and use it in GitHub Desktop.
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
<# | |
Queries the Octopus Deploy API to determine the state of a specific RunbookRun. | |
Possible states include: | |
- Queued | |
- Executing | |
- Success | |
- Failed | |
- TimedOut | |
- Cancelling | |
- Canceled | |
For more info about possible states: | |
https://help.octopus.com/t/full-list-of-servertask-statusses/26243 | |
To use this script, update the variables below with your Octopus URL, an API key and the RunbookRun ID. | |
#> | |
$ErrorActionPreference = "Stop"; | |
# Update the following variables as appropriate | |
$octopusURL = "https://example.octopus.app" | |
$octopusAPIKey = "API-EXAMPLE" # Create one under your user profile in Octopus UI | |
$runbookRunId = "RunbookRuns-123" # Hint: Open the Runbook Run in a web browser, check the URL | |
# Using API Key provided above to create a header to authenticate against the Octopus API | |
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey } | |
# First we need to use the API to find the ServerTask link for the Runbook Run | |
$runbookRun = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/Spaces-1/runbookruns" -Headers $header).Items | Where-Object {($_.Id -like $runbookRunId)} | |
$taskUrlSuffix = $runbookRun.Links.Task | |
$taskUrl = $octopusURL + $taskUrlSuffix | |
# Then we make a second API call to determine the status of the ServerTask | |
$serverTask = (Invoke-RestMethod -Method Get -Uri $taskUrl -Headers $header) | |
$state = $serverTask.State | |
# Logging the results | |
Write-Output "The status of $runBookRun is: $state" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment