Get the FREE Ultimate OpenClaw Setup Guide →

gitlab-variable

npx machina-cli add skill grandcamel/GitLab-Assistant-Skills/gitlab-variable --openclaw
Files (1)
SKILL.md
6.8 KB

CI/CD Variable Skill

CI/CD variable management operations for GitLab using the glab CLI.

Quick Reference

OperationCommandRisk
List variablesglab variable list-
Get variableglab variable get <key>-
Set variableglab variable set <key> <value>⚠️
Update variableglab variable update <key> <value>⚠️
Delete variableglab variable delete <key>⚠️⚠️
Export variablesglab variable export-

Risk Legend: - Safe | ⚠️ Caution | ⚠️⚠️ Warning | ⚠️⚠️⚠️ Danger

When to Use This Skill

ALWAYS use when:

  • User wants to manage CI/CD variables
  • User mentions "variable", "secret", "env var", "CI variable", "environment variable"
  • User wants to configure build/deployment settings

NEVER use when:

  • User wants to run pipelines (use gitlab-ci)
  • User wants to manage .env files locally (use file operations)

Available Commands

List Variables

glab variable list [options]

Options:

FlagDescription
-g, --group=<group>List group-level variables
-P, --per-page=<n>Results per page

Examples:

# List project variables
glab variable list

# List group variables
glab variable list -g mygroup

Get Variable

glab variable get <key> [options]

Options:

FlagDescription
-g, --group=<group>Get from group level
-s, --scope=<scope>Variable scope/environment

Examples:

# Get variable value
glab variable get API_KEY

# Get scoped variable
glab variable get DATABASE_URL --scope=production

Set Variable

glab variable set <key> <value> [options]

Options:

FlagDescription
-g, --group=<group>Set at group level
-m, --maskedMask value in logs
-p, --protectedOnly available in protected branches
-r, --rawValue is raw (no expansion)
-s, --scope=<scope>Variable scope/environment
-t, --type=<type>Variable type: env_var, file

Examples:

# Set simple variable
glab variable set API_URL "https://api.example.com"

# Set masked secret
glab variable set API_KEY "secret123" --masked

# Set protected variable (only on protected branches)
glab variable set DEPLOY_KEY "key123" --protected --masked

# Set scoped variable for production
glab variable set DATABASE_URL "postgres://prod..." --scope=production

# Set file type variable
glab variable set CONFIG_FILE "$(cat config.json)" --type=file

# Set group variable
glab variable set SHARED_SECRET "secret" -g mygroup --masked

Update Variable

glab variable update <key> <value> [options]

Same options as set. Updates existing variable.

Examples:

# Update variable value
glab variable update API_KEY "new-secret" --masked

# Update and change scope
glab variable update DATABASE_URL "new-url" --scope=staging

Delete Variable

glab variable delete <key> [options]

Options:

FlagDescription
-g, --group=<group>Delete from group level
-s, --scope=<scope>Variable scope

Warning: This permanently deletes the variable.

Examples:

# Delete variable
glab variable delete OLD_API_KEY

# Delete scoped variable
glab variable delete DATABASE_URL --scope=staging

Export Variables

glab variable export [options]

Export variables in dotenv format.

Examples:

# Export to stdout
glab variable export

# Export to file
glab variable export > .env.ci

# Export and source
eval $(glab variable export)

Variable Types

TypeUse Case
env_varEnvironment variable (default)
fileWrite value to file, expose path as variable

Variable Flags

FlagEffect
maskedValue is hidden in job logs
protectedOnly available on protected branches/tags
rawNo variable expansion (use for JSON, etc.)

Common Workflows

Workflow 1: Set Up Deployment Variables

# Set production secrets
glab variable set PROD_API_KEY "xxx" --protected --masked --scope=production
glab variable set PROD_DB_URL "postgres://..." --protected --masked --scope=production

# Set staging secrets
glab variable set STAGING_API_KEY "xxx" --masked --scope=staging
glab variable set STAGING_DB_URL "postgres://..." --masked --scope=staging

Workflow 2: Rotate Secrets

# 1. List current variables
glab variable list

# 2. Update the secret
glab variable update API_KEY "new-secret-value" --masked

# 3. Trigger a new pipeline to use new secret
glab ci run

Workflow 3: Set Up Service Account

# Store credentials as masked file
glab variable set SERVICE_ACCOUNT_JSON "$(cat service-account.json)" \
  --type=file --protected --masked

# In CI/CD, use $SERVICE_ACCOUNT_JSON as path to the credentials file

Workflow 4: Configure Multi-Environment

# Production (protected + masked)
glab variable set DATABASE_URL "postgres://prod..." --scope=production --protected --masked
glab variable set API_KEY "prod-key" --scope=production --protected --masked

# Staging
glab variable set DATABASE_URL "postgres://staging..." --scope=staging --masked
glab variable set API_KEY "staging-key" --scope=staging --masked

# Development
glab variable set DATABASE_URL "postgres://dev..." --scope=development
glab variable set API_KEY "dev-key" --scope=development

Security Best Practices

  1. Always mask secrets: Use --masked for any sensitive values
  2. Protect production secrets: Use --protected for production credentials
  3. Use scopes: Separate variables by environment
  4. Rotate regularly: Update secrets periodically
  5. Avoid logging: Never echo variable values in CI scripts
  6. Use file type for complex secrets: JSON, certificates, etc.

Troubleshooting

IssueCauseSolution
Authentication failedInvalid/expired tokenRun glab auth login
Variable not foundWrong key or scopeCheck with glab variable list
Cannot see valueVariable is maskedMasked values cannot be retrieved
Permission deniedNot maintainerNeed maintainer+ role for variables
Value truncatedSpecial charactersUse --raw flag for complex values

Related Documentation

Source

git clone https://github.com/grandcamel/GitLab-Assistant-Skills/blob/main/skills/gitlab-variable/SKILL.mdView on GitHub

Overview

This skill handles GitLab CI/CD variable operations via the glab CLI. It covers listing, retrieving, setting, updating, and deleting CI/CD variables, including secrets and scope controls for projects and groups.

How This Skill Works

The skill uses glab variable commands (list, get, set, update, delete, export) to manage CI/CD variables. It supports project and group scope, masking for secrets, and options like --protected, --scope, and --type to tailor variable behavior.

When to Use It

  • List project or group CI/CD variables with glab
  • Create or set a new CI/CD variable (optionally masked)
  • Update an existing variable (change value, scope, or type)
  • Delete a CI/CD variable (permanently)
  • Manage secrets: masking, protection, or file-type vars

Quick Start

  1. Step 1: Decide the variable key, value, scope (if any), and type (env_var or file)
  2. Step 2: Run the appropriate glab variable command (set/update/get/list/delete) with necessary options
  3. Step 3: Verify the result with glab variable get or glab variable list and review logs

Best Practices

  • Mask secret values with --masked to avoid logging secrets
  • Use --protected for variables on protected branches
  • Specify --scope to limit variable exposure to an environment
  • Use --type=file for file-based values or --type=env_var for standard vars
  • Validate changes by listing or retrieving the variable after update

Example Use Cases

  • List project variables: glab variable list
  • Get a variable value: glab variable get API_KEY
  • Set a masked secret: glab variable set API_KEY "secret123" --masked
  • Set a production-scoped variable: glab variable set DATABASE_URL "postgres://prod..." --scope=production
  • Delete a variable: glab variable delete OLD_API_KEY

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers