Skip to content

Comments

Add gitlab-list-runners.sh to enumerate GitLab runners#1

Open
benhunter wants to merge 1 commit intomasterfrom
codex/add-script-to-enumerate-gitlab-runners
Open

Add gitlab-list-runners.sh to enumerate GitLab runners#1
benhunter wants to merge 1 commit intomasterfrom
codex/add-script-to-enumerate-gitlab-runners

Conversation

@benhunter
Copy link
Owner

Motivation

  • Provide a small admin utility to enumerate all runners attached to a GitLab instance and offer an optional human-readable table output.

Description

  • Add gitlab-list-runners.sh which invokes glab api --paginate "runners/all" and prints raw JSON by default.
  • Add a --table option that requires jq and formats selected fields into TSV which is rendered with column -t for readable output, and include usage/help and argument validation.
  • The script checks for the presence of glab (and jq when --table is requested) and exits with an error if missing.

Testing

  • No automated tests were run for this change.

Codex Task

@benhunter benhunter marked this pull request as ready for review February 21, 2026 20:49
@benhunter benhunter requested a review from Copilot February 21, 2026 20:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.sh with 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'
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.

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.
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.
Comment on lines +58 to +72
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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant