Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions gitlab-list-runners.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash

set -euo pipefail

usage() {
cat <<'EOF'
Usage: gitlab-list-runners.sh [--table]

Enumerate all runners attached to a GitLab instance (admin API).

Requirements:
- glab CLI authenticated to the target GitLab instance
- jq for table output
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- jq for table output
- jq and column for table output

Copilot uses AI. Check for mistakes.

Options:
--table Print a human-readable table instead of raw JSON
-h, --help Show this help message

Examples:
gitlab-list-runners.sh
gitlab-list-runners.sh --table
EOF
}

if ! command -v glab >/dev/null 2>&1; then
echo "Error: glab is required. Install it and run 'glab auth login'." >&2
exit 1
fi

OUTPUT_TABLE=false

while [ "$#" -gt 0 ]; do
case "$1" in
--table)
OUTPUT_TABLE=true
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 1
;;
esac
shift
done

RUNNERS_JSON=$(glab api --paginate "runners/all")
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.

if [ "$OUTPUT_TABLE" = true ]; then
if ! command -v jq >/dev/null 2>&1; then
echo "Error: jq is required for table output." >&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'
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +72
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
else
echo "$RUNNERS_JSON"
fi