You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在jq中通过最后构建分支名称获取对应构建编号

单次jq调用获取最后构建分支的构建编号

给定JSON:

{
  "buildsByBranchName": {
    "origin/master": { "buildNumber": 28694 },
    "master": { "buildNumber": 28563 },
    "refs/remotes/origin/master": { "buildNumber": 4094 }
  },
  "lastBuiltRevision": {
    "branch": [
      { "name": "origin/master" }
    ]
  }
}

可以通过变量绑定的方式在单次jq调用里完成需求,具体命令如下:

jq '.lastBuiltRevision.branch[0].name as $branch | .buildsByBranchName[$branch].buildNumber' input.json

命令解释

  • 先用.lastBuiltRevision.branch[0].name as $branch提取最后构建的分支名称,将其赋值给变量$branch
  • 再通过管道符|连接后续操作,直接用变量$branch作为键,从.buildsByBranchName中取出对应的buildNumber

执行该命令后,输出结果为:

28694

内容的提问来源于stack exchange,提问作者Philippe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 23:07:00