Skip to content

Instantly share code, notes, and snippets.

@cardin
Created February 11, 2021 02:10
Show Gist options
  • Save cardin/71f2c7ac1b1325632e9dc492fee1649b to your computer and use it in GitHub Desktop.
Save cardin/71f2c7ac1b1325632e9dc492fee1649b to your computer and use it in GitHub Desktop.
Offline GitLab Runners are not automatically unregistered, nor is there an easy GUI way to remove them. This script uses GitLab API to remove the runners.
#######################################
# Please replace this values
$gitlabUrl = "https://gitlab.com"
$bearerToken = "abcdefg"
#######################################
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $bearerToken")
$runners = Invoke-RestMethod "$gitlabUrl/api/v4/runners?status=offline" `
-Headers $headers
if ($runners) {
$runners
Pause
} else {
Write-Host "There were no offline runners"
Exit
}
foreach ($runner in $runners) {
$id = $runner.id
Invoke-RestMethod "$gitlabUrl/api/v4/runners/$id" `
-Method DELETE -Headers $headers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment