Automatisation de flux GitLab avec glab CLI

VérifiéPrudence

Gérez les issues, MR, epics, pipelines et appels API GitLab avec le CLI glab. Inclut la configuration multi-instance et l'échappement sécurisé des messages.

Spar Skills Guide Bot
DeveloppementIntermédiaire
29/08/2026
Claude CodeCursorWindsurfCodex
#gitlab#cli#merge-requests#issue-tracking#pipelines

Recommandé pour

Synthèse automatique

Pilote GitLab via la CLI glab : tickets, merge requests, work items, epics, notes, appels REST/GraphQL et inspection des pipelines, avec des consignes précises sur l'échappement shell et la configuration multi-instances.

Points forts

  • Décrit le piège des backticks inline dans -m "..." qui sont exécutés par le shell et publient un contenu tronqué, puis fournit le contournement par heredoc quoté vers un fichier passé en $(cat ...).
  • Explique la détection automatique de l'hôte GitLab depuis le remote, remote_alias pour les remotes secondaires et le rôle de GITLAB_HOST hors dépôt.
  • Couvre dans un seul document les tickets, MR, work items, epics, commentaires, pipelines/jobs et les appels bruts à glab api.
  • Signale les cas limites du shell, notamment le heredoc imbriqué dont le EOF non indenté ferme prématurément le heredoc externe.

Limites

  • Ne traite que la CLI glab : rien sur GitHub/gh ni sur l'interface web GitLab.
  • Suppose glab déjà installé et authentifié, sans expliquer l'installation ni le flux d'authentification initial.
  • Certains choix restent volontairement à la charge de l'agent (chemin du fichier temporaire, configuration GDK), ce qui demande de l'adaptation au contexte.
Quand l'utiliser

À utiliser dès qu'il faut lire ou modifier un ticket, une merge request, une note ou un pipeline GitLab depuis le terminal.

Quand l'éviter

À écarter pour du travail GitHub ou pour de simples opérations git locales sans appel à l'API GitLab.

Analyse de sécurité

Prudence
Score qualité80/100

The content is ordinary GitLab CLI workflow documentation. It uses powerful tools (bash, glab, network API calls) but only for their intended, non-destructive purposes: creating MRs, posting notes, inspecting pipelines. There is no obfuscated payload, no curl|sh, no rm -rf, no attempt to read or exfiltrate tokens, and no instruction to bypass safety checks. The shell-escaping warnings are actually defensive guidance to prevent mangled commands. Hence 'caution' rather than 'risky'.

Points d'attention
  • •Instructs agents to run shell commands (bash heredocs, cat, glab) and make network calls via `glab api`, including POSTs that create issues/MRs/notes — legitimate but state-changing
  • •Tells agents to write messages to temporary files, which could clobber parallel runs if paths collide (skill acknowledges and advises unique paths)
  • •Mentions configuring glab auth/GITLAB_HOST against gitlab.com, self-managed, or GDK instances, i.e. credential-adjacent setup, though no secrets are asked to be printed or transmitted
Comment cette analyse est faite

Exemples

MR comment with inline code
Post a review comment on merge request !412 in org/repo explaining the `client_name` field collision, and include a fenced code block in the body — make sure the backticks survive intact.
Create a labeled issue
Open a GitLab issue on my self-managed instance titled 'Flaky checkout test in CI', label it bug and priority::high, and assign it to me.
Inspect and retry pipeline
Why did the pipeline on main fail? Show me the failing job's log and retry just that job.

name: glab description: GitLab workflow automation using the glab CLI. Use when the user asks to create, update, close, label, or comment on a GitLab issue, merge request, work item, or epic; to post a note, review comment, or discussion reply; to call the GitLab REST or GraphQL API through "glab api"; to inspect or retry pipelines and jobs; or to configure glab auth against gitlab.com, a self-managed instance, or a local GDK. Read it before any glab write operation, because several field flags fail silently - they exit 0 while posting the wrong content. version: 1.12.2 category: Development Workflow license: MIT metadata: audience: developers author: dgruzd workflow: gitlab

GitLab Workflow Skill

GitLab workflow management using glab CLI for merge requests, issues, and Git best practices.

Multiple GitLab Instances

glab auto-detects the GitLab host from your git remote. No GITLAB_HOST is needed when working inside a repository. For non-origin remotes (e.g. a local GDK instance added as a secondary remote), use glab config set remote_alias <remote>. Set GITLAB_HOST only when running outside a git repository or for a one-off command targeting a specific instance. See references/multi-host.md for non-origin remote setup and hostname derivation from remote URLs.

⚠️ Message Escaping — Common Trap

If your message contains backticks (`), $, or other shell special characters, NEVER inline them directly in -m "...". The shell interprets backticks as command substitution, silently mangling your message and producing errors like /bin/bash: line 1: client_name: command not found.

This has caused real production failures: agents posting malformed comments to GitLab MRs/issues, followed by apologetic correction notes.

❌ DON'T — inline backticks in double-quoted -m

# BROKEN: shell tries to execute `client_name` as a command
glab mr note 100 -m "Use `client_name` and `wor/` here." -R org/repo
# Error: /bin/bash: line 1: client_name: command not found
# The comment is posted as: "Use  and  here." (identifiers silently stripped)

# Also BROKEN: backslash-escaped backticks break in nested/scripted contexts
glab mr note 100 -m "Use \`client_name\`" -R org/repo
# Works in simple cases but fails when the command is double-quoted by a caller:
# bash -c "glab mr note 100 -m \"Use \`client_name\`\""  → still executes client_name

✅ DO — write to a file first, then pass via $(cat ...)

Pick a path appropriate for your environment (a mktemp result, a scoped workspace tmp file, whatever fits — the skill doesn't prescribe a specific path; agents choose one that's unique to their invocation to avoid clobbering parallel runs):

# MSG = path you choose (e.g. mktemp, ~/workspace/tmp/note-$$.md, etc.)
MSG=<agent picks>

cat > "$MSG" << 'EOF'
Use `client_name` and `wor/` here. The `glab` tool handles this.
EOF
glab mr note 100 -m "$(cat "$MSG")" -R org/repo

The single-quoted 'EOF' heredoc delimiter prevents ALL variable/backtick expansion when writing the file. The $(cat "$MSG") substitution is safe because the file content is already written literally. Triple-backtick code blocks (```) are also safe inside <<'EOF' heredocs — no escaping needed; only single-backticks and $ trigger command substitution.

✅ Also safe — glab api with -f flag

glab api --method POST "projects/org%2Frepo/merge_requests/100/notes" \
  -f "body=$(cat "$MSG")"

⚠️ Unquoted heredoc still interprets backticks

# BROKEN: unquoted EOF delimiter — backticks in body are still interpreted
cat > "$MSG" << EOF
Use `client_name` here.    # ← shell executes client_name when writing the file
EOF

⚠️ Heredoc-inside-heredoc breaks shell parsing

If your content itself contains a heredoc example with an unindented EOF terminator, the inner EOF at column 0 closes the outer heredoc early:

# BROKEN: the inner EOF is at column 0 — it closes the OUTER heredoc early
cat > "$OUTER" << 'EOF'
Here is the safe pattern:
cat > "$MSG" << 'EOF'
Use `client_name` here.
EOF
# ↑ This EOF terminates the OUTER heredoc — the lines below run as shell commands!
echo "more content..."
EOF
# ↑ This stray EOF becomes a command: "EOF: command not found"

Fix — use a different delimiter for the outer heredoc:

cat > "$OUTER" << 'OUTEREOF'
Here is the safe pattern:
  cat > "$MSG" << 'EOF'
  Use `client_name` here.
  EOF
OUTEREOF

Or write the file in chunks — first chunk uses >, subsequent chunks use >>, each with its own delimiter.

Rule of thumb: If the message contains `, $, !, or \ — write to a file with << 'EOF' first, always. If the content itself contains heredoc syntax, use a unique outer delimiter (e.g. OUTEREOF, MSGEOF) that won't appear in the body.

Creating Merge Requests

Always pass --push and -H <owner/repo>. Without --push, the branch may not exist on any remote yet. Without -H, glab may pick the wrong remote (e.g. a security mirror) as the source project, creating the MR from the wrong fork.

Second same-family remote? In a checkout with both origin (gitlab-org/gitlab) and a security mirror (gitlab-org/security/gitlab), glab mr create run non-interactively (no TTY, how agents run) silently picks the security fork as the head and fails with 400 {source_branch: [does not exist]}. Durable fix, set once per checkout: git config remote.origin.glab-resolved-head head. Per-command fallback for fresh checkouts: pass -H <owner/repo> (e.g. -H gitlab-org/gitlab). -R does not fix this — it pins only the base repo, not the head.

# Simple MR
glab mr create --push -H <owner/repo> --title "Add feature" --description "Brief description" --assignee <username>

# Complex MR - write description to file first (pick your own path)
glab mr create --push -H <owner/repo> --title "Add feature" --description "$(cat "$DESC")" --assignee <username>

Templates: Check .gitlab/merge_request_templates/ for project-specific templates.

Full flag list (Claude Code injects this automatically; other agents should run it):

!glab mr create --help

Updating Merge Requests

glab mr update <number> --description "$(cat "$DESC")"
glab mr view <number> -R <owner>/<repo>

Issue Management

The full, always-current flag list (Claude Code injects this automatically; other agents should run it):

!glab issue --help

view, note, list, create, update work as you'd expect. The non-obvious traps that --help won't warn you about:

# List is open by default and has NO --state flag — use --closed / --all instead
glab issue list --closed -R <owner>/<repo>
glab issue list --all    -R <owner>/<repo>

# Labels — use --label / --unlabel, NEVER +label or -label syntax
glab issue update 123 --label "new-label"
glab issue update 123 --unlabel "old-label"
# Scoped labels auto-replace within their scope — no --unlabel needed:
glab issue update 123 --label "status::doing"   # removes any existing status:: label

# Messages with backticks/$ — write to a file first (see Message Escaping above)
glab issue note <number> -m "$(cat "$MSG")" -R <owner>/<repo>

For issue state transitions (close/reopen via API) and posting notes via glab api: references/issue-api.md

Work Items

GitLab is migrating issues to work items. The URL shows /work_items/<iid> but the REST API is the same.

# ✅ Use the issues API — same IID, same endpoints
glab api --method GET "projects/org%2Fproject/issues/<iid>"

# ❌ /work_items/ REST endpoint does not exist
glab api --method GET "projects/org%2Fproject/work_items/<iid>"   # → 404

URL parsing: https://gitlab.com/org/project/-/work_items/539076 → glab api "projects/org%2Fproject/issues/539076"

Full details, GraphQL alternative, group-level work items, and the agent plan (Workplan) widget: references/work-items.md

MR Review

Since glab v1.94.0, glab mr note handles every common MR-comment shape (list, general, diff-line, reply, resolve/reopen) without raw glab api calls or hand-built position objects. Prefer it for any single-comment workflow. The MR IID is a positional argument (not --mr); omit it to auto-detect from the current branch.

# ✅ Use glab mr note for read/write/reply/resolve — single command per operation
glab mr note list 123 -F json                                       # read discussions
glab mr note create 123 -m "comment"                                # general
glab mr note create 123 --file main.go --line 42 -m "..."           # diff comment
glab mr note create 123 --reply abc12345 -m "..."                   # reply
glab mr note resolve 123 abc12345                                   # resolve thread

# ❌ Do NOT use glab api .../discussions for these operations
glab api --method GET "projects/<id>/merge_requests/123/discussions"             # use mr note list
glab api --method PUT ".../discussions/<id>" -f resolved=true       # use mr note resolve

Full flag list for the subcommands above (Claude Code injects this automatically; other agents should run it):

!glab mr note --help

Fall back to raw glab api .../draft_notes only for batched draft reviews (multiple inline comments published together via bulk_publish) — glab mr note has no draft mode.

Full reference (all flags, code suggestions, drafts/batch fallback, position objects): references/mr-review.md

Issue Links, Epics, and Nested Groups

MR Listing and Filtering

Full flag list (Claude Code injects this automatically; other agents should run it):

!glab mr list --help

Note: glab mr list lists open MRs by default and has no --state or --status flag — use --all, --merged, or --closed to change the state filter.

Search

For full search examples (instance / group / project, scope table, pagination): references/search.md

Quick reference:

glab api --method GET "search?scope=issues&search=<query>" | jq '.[] | {iid, title}'
glab api --method GET "groups/<group>/search?scope=merge_requests&search=<query>" | jq '.[]'
glab api --method GET "projects/<org>%2F<repo>/search?scope=issues&search=<query>" | jq '.[]'

Git and Commit Conventions

Follow the repo's own git conventions when present (a project may document them and enforce them with a commit linter). GitLab defaults:

git checkout -b feature/description   # feature branches
git checkout -b fix/description       # bug fixes
  • Capitalized, imperative commit subjects ("Add feature", not "Added feature" or "feat: add feature"); GitLab does not use conventional-commit subjects.
  • Reference issues/MRs with full URLs: Closes https://gitlab.com/org/project/-/issues/123.
  • Single-quote commit messages containing special characters: git commit -m 'Add note from https://gitlab.com/org/project/-/merge_requests/123'.

Agent Guidelines

The sections above cover the common workflows. These are the non-obvious traps and API quirks that are easy to get wrong and not discoverable from glab <cmd> --help:

  1. Read context first — glab issue view / glab mr view before implementing; check .gitlab/issue_templates/ and .gitlab/merge_request_templates/ for templates
  2. --jq works on subcommands, not on glab api — glab issue list/glab mr list/glab ci list accept a global --jq flag (filters JSON output); glab api does not — pipe its output through | jq '...' instead
  3. No --body flag — glab uses --description, not --body (which is a gh flag); they are not interchangeable
  4. Work items use the issues API — /work_items/<iid> URLs → projects/.../issues/<iid>; the /work_items/ REST endpoint is a 404
  5. Epic comments need GraphQL — REST /notes GET+POST both → 404 (still true on GitLab 19.1); pass body/noteableId as GraphQL variables, never string-interpolate. See references/epic-comments.md
  6. No -R for group-level API — -R expects OWNER/REPO; group endpoints use glab api "groups/..." directly
  7. Nested groups REST: %2F — groups/org%2Fsubgroup/epics; unencoded slashes → 404
  8. GraphQL iid is a String — workItem(iid: "16428") not workItem(iid: 16428)
  9. groups/<id>/work_items is 404 — use groups/<id>/epics (REST) or GraphQL
  10. project exposes workItems (plural), not workItem — under project use workItems(first: 1, iid: "IID") with no filter: argument; the singular workItem(iid:) field exists only under group/namespace
  11. Epic close/reopen via REST — state_event=close/reopen on PUT groups/<id>/epics/<iid> works; no GraphQL needed
  12. Scoped labels auto-replace — --label "status::doing" removes any existing status::* label; no --unlabel needed (this is a platform fact, true via the API generally, not just glab)
  13. Idempotent comments → --unique — glab mr note create -m "..." --unique skips posting if an identical body already exists; matches on body only, so identical bodies on different diff lines still post
  14. Non-origin remotes → remote_alias — if origin points at one instance but you want glab to target another remote (e.g. a local GDK added as gdk), run glab config set remote_alias gdk rather than setting GITLAB_HOST per command. See references/multi-host.md
  15. Backticks in messages → write to a file first — never inline `/$ in -m "..." or --description "..."; write to a file you name (unique per invocation) using << 'EOF' (single-quoted delimiter, critical), then pass via $(cat "$FILE"). See the Message Escaping section above.
  16. Second same-family remote misroutes mr create — with a security mirror alongside origin, non-interactive mr create (no TTY) silently picks the fork as the head. Fix once per checkout: git config remote.origin.glab-resolved-head head; per-command fallback: -H <owner/repo> (-R does not fix it). See the "Creating Merge Requests" section.
  17. glab api note body: file → -F "body=@file"; prose with backticks/$ → write it literally to a file first. Inline text → -f; literal @here see above → -f "body=@here see above" (never a file). Nested JSON → --input file -H "Content-Type: application/json". Repair: --method PUT -F "body=@file", not DELETE. Failures are silent (exit 0, HTTP 201); verify what landed with | jq '.body | length'. Details: references/mr-review.md.
  18. Always use full URLs in note/comment bodies (e.g. https://gitlab.com/org/project/-/issues/123) instead of short references (#123). This applies to issues, merge requests, epics, and so on. Short refs resolve against project context and render as literal text on group-level items (epics, group work items); full URLs expand everywhere.

Contributing Improvements

This skill is maintained in the GitLab monolith (gitlab-org/gitlab, under .claude/skills/glab/) and synced out to gitlab-org/ai/skills — the monolith copy is the source of truth. If you discover that any guidance here is inaccurate or outdated (e.g. a command that no longer works, a wrong flag, an incorrect API behavior), confirm with the user and open an MR against the monolith with the fix. Keep changes focused — one fix per MR.

Du fichier au premier essai

Le téléchargement contient exactement le contenu affiché sur cette fiche. Cette copie peut différer de la dernière version du dépôt source.

Consulter la source et ses fichiers annexes

Ce téléchargement contient uniquement SKILL.md. Les scripts, références, modèles et dépendances éventuels ne sont pas inclus. Récupérez les fichiers nécessaires depuis la source en conservant leur arborescence avant de poursuivre.

1. Télécharger le fichier

Télécharger SKILL.md

Depuis la racine d’un projet de test, enregistrez le fichier sous .skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md, ou utilisez la commande suivante. Ce dossier sert à examiner la skill avant son installation.

Commande pour macOS/Linux ou WSL : un shell POSIX et curl sont nécessaires. Sous Windows sans WSL, utilisez le bouton de téléchargement et créez le dossier manuellement.

mkdir -p '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/gitlab-workflow-automation-with-glab-cli-mte1lfvc/download' --output '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md.part' && mv '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md.part' '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md'

2. Vérifier les prérequis

Lisez SKILL.md avant de l’utiliser. Si le fichier cite des scripts ou services externes, examinez-les et préparez les accès nécessaires dans votre environnement de test.

Aucune section de prérequis reconnue dans ce fichier. Cela ne signifie pas qu’il est autonome : les bibliothèques, outils et accès peuvent être cités ailleurs dans le contenu ou dans le dépôt source.

Les plateformes de la fiche sont des indications du catalogue. Les chemins ci-dessous suivent la documentation des outils ; ils ne prouvent pas que cette skill y a été exécutée. Aucune version minimale de ces outils n’est attestée pour cette fiche.

3. Charger la skill

Après vérification, copiez le dossier complet dans le projet avec l’une des commandes ci-dessous, puis ouvrez une nouvelle session de l’outil. La commande s’arrête si un dossier du même nom existe déjà : comparez les fichiers avant de le remplacer.

Claude Code
test -f '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md' && test -s '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/glab' && cp -R '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc' '.claude/skills/glab'

Cursor
test -f '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md' && test -s '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/glab' && cp -R '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc' '.cursor/skills/glab'

Codex
test -f '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md' && test -s '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/glab' && cp -R '.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc' '.agents/skills/glab'

OpenSkills

OpenSkills doit déjà être installé. La procédure locale install/read est contrôlée avec OpenSkills 1.5.0, qui exige Node.js ≥ 20.6.0. Aucun slug du catalogue n’est résolu automatiquement.

Installation officielle d’OpenSkills
openskills install './.skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc'

openskills read 'gitlab-workflow-automation-with-glab-cli-mte1lfvc'

La lecture doit afficher le contenu du fichier installé et son dossier de base. Elle ne lance ni la skill ni ses dépendances.

Pour un agent qui lit AGENTS.md, synchronisez ensuite l’index. Cette commande modifie AGENTS.md : relisez le diff avant de l’utiliser.

openskills sync

Mode manuel ou autre outil : joignez SKILL.md à une conversation, ou ouvrez-le dans un agent capable de lire les fichiers. Ajoutez les ressources annexes nécessaires. Il n’existe pas de dossier universel reconnu par tous les outils.

4. Faire un premier essai

Utilisez une entrée courte et fictive : un endpoint d’API, un petit document ou un brief d’interface. Dans une nouvelle conversation, joignez le fichier ou donnez son chemin à l’agent, puis adaptez cette demande :

Lis .skill-downloads/gitlab-workflow-automation-with-glab-cli-mte1lfvc/SKILL.md et applique ses instructions à cet exemple : [décrire une entrée de test]. Indique les fichiers, dépendances ou accès qui manquent. Produis le résultat demandé par la skill sans inventer de données ni exécuter de script non examiné.

Résultat attendu : une sortie correspondant aux instructions de la skill, ou une liste précise des prérequis manquants. Une simple confirmation de lecture ne valide pas le premier usage. Si une ressource externe est indisponible, ce parcours reste à tester.

Skills similaires