Add gitlab-list-runners.sh to enumerate GitLab runners#1
Add gitlab-list-runners.sh to enumerate GitLab runners#1
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new admin utility script gitlab-list-runners.sh to enumerate all GitLab runners attached to a GitLab instance. The script uses the GitLab CLI (glab) to query the admin API and provides both raw JSON output and an optional human-readable table format.
Changes:
- Added
gitlab-list-runners.shwith argument parsing, command availability checks, and two output modes (raw JSON and formatted table)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| printf "ID\tDescription\tStatus\tType\tActive\tShared\tIP\tLast Contact\n"; | ||
| cat; | ||
| } \ | ||
| | column -t -s $'\t' |
There was a problem hiding this comment.
The 'column' command may not be available on all systems by default. Consider adding a check for 'column' availability when '--table' is requested, similar to how 'jq' is checked. This will provide a clearer error message if the command is missing.
|
|
||
| Requirements: | ||
| - glab CLI authenticated to the target GitLab instance | ||
| - jq for table output |
There was a problem hiding this comment.
The Requirements section lists 'jq for table output' but does not mention that the 'column' command is also required for table formatting. This should be added to the requirements to accurately inform users of all dependencies.
| - jq for table output | |
| - jq and column for table output |
| shift | ||
| done | ||
|
|
||
| RUNNERS_JSON=$(glab api --paginate "runners/all") |
There was a problem hiding this comment.
The variable RUNNERS_JSON captures the output of the glab command, but if the command fails or returns an error, the script will exit due to 'set -e' before any meaningful error message can be shown. Consider adding error handling around the API call to provide a more helpful error message, such as checking if glab authentication is configured or if the user has admin permissions.
| RUNNERS_JSON=$(glab api --paginate "runners/all") | |
| if ! RUNNERS_JSON=$(glab api --paginate "runners/all"); then | |
| echo "Error: failed to list GitLab runners via glab API." >&2 | |
| echo "Make sure glab is authenticated to the target instance (run 'glab auth login')" >&2 | |
| echo "and that your user has administrator permissions to access the runners API." >&2 | |
| exit 1 | |
| fi |
| echo "$RUNNERS_JSON" | jq -r '.[] | [ | ||
| (.id | tostring), | ||
| (.description // "-"), | ||
| (.status // "-"), | ||
| (.runner_type // "-"), | ||
| (.active | tostring), | ||
| (.is_shared | tostring), | ||
| (.ip_address // "-"), | ||
| (.contacted_at // "-") | ||
| ] | @tsv' \ | ||
| | { | ||
| printf "ID\tDescription\tStatus\tType\tActive\tShared\tIP\tLast Contact\n"; | ||
| cat; | ||
| } \ | ||
| | column -t -s $'\t' |
There was a problem hiding this comment.
If the GitLab API returns an empty array for runners, the jq command '.[]' will produce no output, resulting in only the header line being displayed in table mode. While this is technically correct behavior, consider adding a check to inform the user when no runners are found to avoid confusion.
Motivation
Description
gitlab-list-runners.shwhich invokesglab api --paginate "runners/all"and prints raw JSON by default.--tableoption that requiresjqand formats selected fields into TSV which is rendered withcolumn -tfor readable output, and include usage/help and argument validation.glab(andjqwhen--tableis requested) and exits with an error if missing.Testing
Codex Task