如何自定义GitHub Actions审核部署界面,明确待审批部署详情
解决方案:在GitHub Actions审批界面提前展示部署关键信息
要让审核者在审批前清晰区分多个待部署任务,不能依赖environment.url(该字段仅审批后显示),可以通过以下几种方式将环境、区域、自定义字符串等关键信息提前展示:
1. 动态生成带关键信息的环境名称
直接把环境、区域、租户ID等信息拼接进environment.name,审批界面的环境字段会直接显示这些内容,一眼就能区分不同任务:
environment: name: ${{format('{0}-{1}-tenant-{2}', github.event.inputs.environment, github.event.inputs.region, github.event.inputs.tenant_id)}}
示例生成的环境名称:staging-us-west-2-tenant-001
2. 给审批步骤添加自定义描述
在使用环境审批的job中,添加description字段,把关键信息明确写入,该描述会直接显示在审批界面:
jobs: deploy: runs-on: ubuntu-latest environment: name: ${{format('{0}-{1}-tenant-{2}', github.event.inputs.environment, github.event.inputs.region, github.event.inputs.tenant_id)}} description: "待审批部署:环境=${{github.event.inputs.environment}},区域=${{github.event.inputs.region}},租户ID=${{github.event.inputs.tenant_id}}" steps: - name: 执行部署 run: echo "开始部署到目标环境..."
3. 自定义工作流运行名称
在工作流开头设置动态生成的name,这样在GitHub Actions的运行列表里就能先区分不同的待审批任务,再进入详情页审批:
name: ${{format('部署到 {0}({1})- 租户 {2}', github.event.inputs.environment, github.event.inputs.region, github.event.inputs.tenant_id)}} on: workflow_dispatch: inputs: environment: description: '目标环境' required: true region: description: '目标区域' required: true tenant_id: description: '租户ID' required: true jobs: deploy: runs-on: ubuntu-latest environment: name: ${{format('{0}-{1}-tenant-{2}', github.event.inputs.environment, github.event.inputs.region, github.event.inputs.tenant_id)}} description: "待审批部署:环境=${{github.event.inputs.environment}},区域=${{github.event.inputs.region}},租户ID=${{github.event.inputs.tenant_id}}" steps: - name: 执行部署 run: echo "部署中..."
以上方法组合使用,能让审核者在审批前的运行列表、审批详情页都清晰看到每个待审批任务的核心信息,轻松区分多个并行的部署请求。
内容的提问来源于stack exchange,提问作者Pallavi Mistry
相关产品推荐
相关产品推荐

