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

如何调试GitHub Actions中无日志的构建任务失败问题?

GitHub Actions无GUI查看失败任务日志方法

问题背景

我正在学习使用GitHub Actions,配置了一个在三种架构上构建代码的任务,YAML标签取自官方runner-images页面。配置的Workflow代码如下:

name: Build Artifacts

on: [push]

jobs:
  build-linux-artifact:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: make
      run: make

  build-osx-intel-artifact:
    runs-on: macos-latest-large

    steps:
    - uses: actions/checkout@v4
    - name: make
      run: make

  build-osx-arm-artifact:
    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v4
    - name: make
      run: make

其中两个任务运行正常,但build-osx-arm-artifact任务立即失败,且失败页面无日志展示,尝试官方文档步骤后仍无日志,需要非GUI方式查看日志。

非GUI查看日志的方法

1. GitHub CLI(人工操作)

先安装并登录GitHub CLI,执行以下命令:

  • 列出仓库的Workflow运行记录,找到目标失败运行的ID:
    gh run list --repo <你的仓库全名>
    
  • 查看指定任务的日志,可直接输出或导出到文件:
    # 直接查看日志
    gh run view <运行ID> --job build-osx-arm-artifact --log
    
    # 导出日志到文件
    gh run view <运行ID> --job build-osx-arm-artifact --log > arm-build-log.txt
    

2. GitHub REST API(程序化操作)

需要生成带actions权限的个人访问令牌(PAT),然后通过以下方式获取日志:

  • 使用curl下载任务日志(返回ZIP压缩包):
    curl -H "Authorization: token <你的PAT>" \
    https://api.github.com/repos/<用户名>/<仓库名>/actions/jobs/<任务ID>/logs \
    > job-logs.zip
    

解压ZIP包即可查看完整日志内容。

注:任务ID可通过gh run view <运行ID>命令查看,或在失败页面的URL中提取(URL末尾的数字即为任务ID)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 15:00:20