有没有办法在运行 gh 操作时获取工作流程 id

问题描述 投票:0回答:2

我在运行 GitHub 操作时生成这种格式的工作流程日志

${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}.log

我想获取我们在其余调用中看到的工作流程 ID

"workflow_runs": [
    {
      "id": 30433642,
       "name": "Build",
    }
  ]

在这里检查:https://docs.github.com/en/actions/learn-github-actions/contexts#github-context

有没有办法我们可以在运行 gh 操作时获取工作流程 id?

github continuous-integration github-actions
2个回答
4
投票

是的,这是可能的。

您可以从工作流程Github Context获取run_id

PR 事件中的 Github 上下文示例:

{
  "token": "***",
  "job": "github-context",
  "ref": "refs/pull/16/merge",
  "sha": "b4f1729888b5c99abdf8a7a250ecc6cff1e180be",
  "repository": "GuillaumeFalourd/poc-github-actions",
  "repository_owner": "GuillaumeFalourd",
  "repositoryUrl": "git://github.com/GuillaumeFalourd/poc-github-actions.git",
  "run_id": "974568708",
  "run_number": "2",
  "retention_days": "90",
  "actor": "GuillaumeFalourd",
  "workflow": "24 - Github Context",
  "head_ref": "feature/readme",
  "base_ref": "main",
  "event_name": "pull_request",
  "event": {...}
} 

0
投票

通过 docs 对此答案的更新如下: ${{ github.run_id }}

© www.soinside.com 2019 - 2024. All rights reserved.