Created
February 11, 2021 02:10
-
-
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.
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
####################################### | |
# 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