Loading...
Loading...
GitLab CI/CD variable operations. ALWAYS use this skill when user wants to: (1) list CI/CD variables, (2) set/create variables, (3) update variables, (4) delete variables, (5) manage secrets.
npx skill4agent add grandcamel/gitlab-assistant-skills gitlab-variableglab| Operation | Command | Risk |
|---|---|---|
| List variables | | - |
| Get variable | | - |
| Set variable | | ⚠️ |
| Update variable | | ⚠️ |
| Delete variable | | ⚠️⚠️ |
| Export variables | | - |
glab variable list [options]| Flag | Description |
|---|---|
| List group-level variables |
| Results per page |
# List project variables
glab variable list
# List group variables
glab variable list -g mygroupglab variable get <key> [options]| Flag | Description |
|---|---|
| Get from group level |
| Variable scope/environment |
# Get variable value
glab variable get API_KEY
# Get scoped variable
glab variable get DATABASE_URL --scope=productionglab variable set <key> <value> [options]| Flag | Description |
|---|---|
| Set at group level |
| Mask value in logs |
| Only available in protected branches |
| Value is raw (no expansion) |
| Variable scope/environment |
| Variable type: env_var, file |
# 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 --maskedglab variable update <key> <value> [options]set# Update variable value
glab variable update API_KEY "new-secret" --masked
# Update and change scope
glab variable update DATABASE_URL "new-url" --scope=stagingglab variable delete <key> [options]| Flag | Description |
|---|---|
| Delete from group level |
| Variable scope |
# Delete variable
glab variable delete OLD_API_KEY
# Delete scoped variable
glab variable delete DATABASE_URL --scope=stagingglab variable export [options]# Export to stdout
glab variable export
# Export to file
glab variable export > .env.ci
# Export and source
eval $(glab variable export)| Type | Use Case |
|---|---|
| Environment variable (default) |
| Write value to file, expose path as variable |
| Flag | Effect |
|---|---|
| Value is hidden in job logs |
| Only available on protected branches/tags |
| No variable expansion (use for JSON, etc.) |
# 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# 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# 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# 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--masked--protected| Issue | Cause | Solution |
|---|---|---|
| Authentication failed | Invalid/expired token | Run |
| Variable not found | Wrong key or scope | Check with |
| Cannot see value | Variable is masked | Masked values cannot be retrieved |
| Permission denied | Not maintainer | Need maintainer+ role for variables |
| Value truncated | Special characters | Use |