【问题标题】:GitHub Actions: How to access to the log of current build via TerminalGitHub Actions:如何通过终端访问当前构建的日志
【发布时间】:2020-09-09 06:07:29
【问题描述】:

我正在尝试熟悉 Github Actions。我已经以某种方式配置了我的工作流程,每次我将代码推送到 GitHub 时,代码都会自动构建并推送到 heroku。

不去github.com如何在终端访问构建日志信息?

【问题讨论】:

    标签: github build github-actions


    【解决方案1】:

    使用最新的cli/cli tool named gh (1.9.0+),您可以轻松做到
    (从你的终端,没有github.com):

    gh run view <jobId> --log 
    # or
    gh run view <jobId> --log-failed
    

    见“Work with GitHub Actions in your terminal with GitHub CLI

    使用新的 gh run list,您可以概览所有类型的工作流运行,无论它们是通过推送、拉取请求、Webhook 还是手动事件触发的。

    要深入了解单次运行的详细信息,您可以使用 gh run view,可以选择深入了解与作业的各个步骤一样多的详细信息。

    对于更神秘的故障,您可以将 grep 之类的工具与 gh run view --log 结合使用,以搜索运行的整个日志输出。

    如果--log 信息过多,gh run --log-failed 将仅输出失败的各个步骤的日志行。
    这非常适合直接查看失败步骤的日志,而不必自己运行grep

    对于GitHub CLI 2.4.0(2021 年 12 月),gh run list 带有用于 JSON 导出的 --json 标志。

    【讨论】:

    • 喜欢这个功能
    【解决方案2】:

    使用

    curl \
      -H "Accept: application/vnd.github.v3+json" \
      https://api.github.com/repos/<github-user>/<repository>/actions/workflows/<workflow.yaml>/runs
    

    https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs

    这将返回具有以下结构的 JSON:

    {
      "total_count": 1,
      "workflow_runs": [
        {
          "id": 30433642,
          "node_id": "MDEyOldvcmtmbG93IFJ1bjI2OTI4OQ==",
          "head_branch": "master",
          "head_sha": "acb5820ced9479c074f688cc328bf03f341a511d",
          "run_number": 562,
          "event": "push",
          "status": "queued",
          "conclusion": null,
          "workflow_id": 159038,
          "url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642",
          "html_url": "https://github.com/octo-org/octo-repo/actions/runs/30433642",
          "pull_requests": [],
          "created_at": "2020-01-22T19:33:08Z",
          "updated_at": "2020-01-22T19:33:08Z",
          "jobs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/jobs",
          "logs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/logs",
          "check_suite_url": "https://api.github.com/repos/octo-org/octo-repo/check-suites/414944374",
          "artifacts_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/artifacts",
          "cancel_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/cancel",
          "rerun_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/rerun",
          "workflow_url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/159038",
          "head_commit": {...},
          "repository": {...},
          "head_repository": {...}
      ]
    }
    

    使用具有存储库管理员权限的 PAT 访问 jobs_url

    【讨论】:

      猜你喜欢
      • 2014-11-17
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 2022-10-20
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多