mcpField
G
glab-variable

glab-variable

github.com/vince-winkintel云与 DevOps49107 次安装1 天前更新
代码仓库

关于 glab-variable

glab-variable 是用于管理 GitLab 项目和群组 CI/CD 变量的 glab 命令行技能,支持继承查找与变量导入导出,并可在更新时保留未指定的属性。

主要功能

  1. 01读取继承的变量
  2. 02创建和更新变量
  3. 03导出与导入变量数据
  4. 04设置群组变量的屏蔽与隐藏

适用场景

  1. 01查找项目或上级群组中的变量
  2. 02在项目或群组间迁移变量
  3. 03更新变量时保留未指定的属性

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/vince-winkintel/gitlab-cli-skills --skill glab-variable

安装后在 Claude Code 中输入/glab-variable确认已加载。

附带文件references/commands.md

详细介绍

glab variable

继承读取与部分更新

variable get KEY --inherited 会先查询所选项目或群组,然后从距离最近的父群组开始查询,最后查询实例变量。对于缺失或无法读取的层级(404/401/403),会跳过;其他错误则会返回。--scope 会筛选项目/群组变量,但不会筛选实例变量。这是对已存储定义的查询,并非对所有 CI 变量优先级规则的完整模拟。文本和 JSON 输出都可能暴露机密值;仅将其发送给经批准的接收方。

variable update 会保留未指定的可选属性。省略 --protected、--masked、--raw、--type 和 --description 时,会保留这些属性的现有值。只有在批准更改相关策略时,才使用 --protected=false 这类明确的布尔值。值仍需通过位置参数、--value 或标准输入提供;不要在标准输入为空时将其作为仅更新元数据的操作调用,否则可能会将值替换为空字符串。--scope 会保留现有的目标范围行为。

概览


  Variables store configuration and secrets used by CI/CD pipelines.

  Each subcommand acts on the current project by default. Use
  `--group` to manage a group's variables instead.
         
  USAGE  
         
    glab variable [command] [--flags]  
            
  COMMANDS  
            
    delete <key> [--flags]          Delete a variable for a project or group.
    export [--flags]                Export variables from a project or group.
    get <key> [--flags]             Get a variable for a project or group.
    import [--flags]                Import variables from a JSON file or standard input.
    list [--flags]                  List variables for a project or group.
    set <key> <value> [--flags]     Create a new variable for a project or group.
    update <key> <value> [--flags]  Update an existing variable for a project or group.
         
  FLAGS  
         
    -h --help                       Show help for this command.
    -R --repo                       Select another repository. Can use either `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format. Also accepts full URL or Git URL.

快速开始

glab variable --help

导出和导入变量

glab variable import 使用与 glab variable export --output json 输出相同的 JSON 数组结构。默认从标准输入读取,也可以通过 --input-file / -i 指定文件。

# Preview and preserve an export before importing it elsewhere
glab variable export --output json > variables.json
glab variable import --input-file variables.json -R group/target-project

# Pipe between groups
glab variable export --group source-group |
  glab variable import --group target-group

# Continue when target variables already exist
glab variable import --input-file variables.json --skip-existing

如果目标变量已存在,导入会停止,除非设置了 --skip-existing。导出内容会省略隐藏变量的值,因此导入时会跳过这些条目并发出警告;请从经批准的机密来源获取值,并使用 glab variable set --hidden 明确重新创建。请将导出文件视为敏感文件,勿将其纳入版本控制,并在导入前确认目标项目或群组。

掩码和隐藏的群组变量

glab variable set 现在会正确地为群组级变量传递 --masked 和 --hidden。请使用明确的标志,确认目标群组,并在确认时绝不打印值:

glab variable set DEPLOY_TOKEN "$DEPLOY_TOKEN" \
  --group group/subgroup \
  --masked \
  --hidden \
  --protected

# Inspect only approved metadata; the raw JSON includes the value
glab variable get DEPLOY_TOKEN --group group/subgroup --output json \
  --jq '{key, protected, masked, hidden, environment_scope}'

掩码和隐藏是由服务端强制执行的属性,不能替代最小权限原则或轮换。如果 GitLab 因值不符合掩码规则而拒绝该值,不要暗中放宽设置;应修正值的格式,或获得操作员对其他策略的明确批准。

子命令

完整的 --help 输出请参阅 references/commands.md。

评论

支持 Markdown