工作流作业的 REST API 端点
使用 REST API 与 GitHub Actions 中的工作流作业进行交互。
关于 GitHub Actions 中的工作流作业
您可以使用 REST API 查看 GitHub Actions 中的日志和工作流作业。工作流作业是在同一运行器上执行的一组步骤。有关更多信息,请参阅“GitHub Actions 的工作流语法”。
获取工作流运行的作业
获取工作流运行中的特定作业。
任何拥有仓库读取权限的人都可以使用此端点。
如果仓库是私有的,OAuth 令牌和个人访问令牌(经典)需要 `repo` 范围才能使用此端点。
用于“获取工作流运行作业”的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- “操作”仓库权限(读取)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。
用于“获取工作流运行作业”的参数
名称,类型,描述 |
---|
accept string 建议设置为 `application/vnd.github+json`。 |
名称,类型,描述 |
---|
owner string 必需仓库的帐户所有者。名称不区分大小写。 |
repo string 必需仓库的名称,不包含 `.git` 扩展名。名称不区分大小写。 |
job_id integer 必需作业的唯一标识符。 |
用于“获取工作流运行作业”的 HTTP 响应状态代码
状态代码 | 描述 |
---|---|
200 | OK |
用于“获取工作流运行作业”的代码示例
请求示例
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/jobs/JOB_ID
响应
状态:200
{
"id": 399444496,
"run_id": 29679449,
"run_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/29679449",
"node_id": "MDEyOldvcmtmbG93IEpvYjM5OTQ0NDQ5Ng==",
"head_sha": "f83a356604ae3c5d03e1b46ef4d1ca77d64a90b0",
"url": "https://api.github.com/repos/octo-org/octo-repo/actions/jobs/399444496",
"html_url": "https://github.com/octo-org/octo-repo/runs/29679449/jobs/399444496",
"status": "completed",
"conclusion": "success",
"started_at": "2020-01-20T17:42:40Z",
"completed_at": "2020-01-20T17:44:39Z",
"name": "build",
"steps": [
{
"name": "Set up job",
"status": "completed",
"conclusion": "success",
"number": 1,
"started_at": "2020-01-20T09:42:40.000-08:00",
"completed_at": "2020-01-20T09:42:41.000-08:00"
},
{
"name": "Run actions/checkout@v2",
"status": "completed",
"conclusion": "success",
"number": 2,
"started_at": "2020-01-20T09:42:41.000-08:00",
"completed_at": "2020-01-20T09:42:45.000-08:00"
},
{
"name": "Set up Ruby",
"status": "completed",
"conclusion": "success",
"number": 3,
"started_at": "2020-01-20T09:42:45.000-08:00",
"completed_at": "2020-01-20T09:42:45.000-08:00"
},
{
"name": "Run actions/cache@v3",
"status": "completed",
"conclusion": "success",
"number": 4,
"started_at": "2020-01-20T09:42:45.000-08:00",
"completed_at": "2020-01-20T09:42:48.000-08:00"
},
{
"name": "Install Bundler",
"status": "completed",
"conclusion": "success",
"number": 5,
"started_at": "2020-01-20T09:42:48.000-08:00",
"completed_at": "2020-01-20T09:42:52.000-08:00"
},
{
"name": "Install Gems",
"status": "completed",
"conclusion": "success",
"number": 6,
"started_at": "2020-01-20T09:42:52.000-08:00",
"completed_at": "2020-01-20T09:42:53.000-08:00"
},
{
"name": "Run Tests",
"status": "completed",
"conclusion": "success",
"number": 7,
"started_at": "2020-01-20T09:42:53.000-08:00",
"completed_at": "2020-01-20T09:42:59.000-08:00"
},
{
"name": "Deploy to Heroku",
"status": "completed",
"conclusion": "success",
"number": 8,
"started_at": "2020-01-20T09:42:59.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
},
{
"name": "Post actions/cache@v3",
"status": "completed",
"conclusion": "success",
"number": 16,
"started_at": "2020-01-20T09:44:39.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
},
{
"name": "Complete job",
"status": "completed",
"conclusion": "success",
"number": 17,
"started_at": "2020-01-20T09:44:39.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
}
],
"check_run_url": "https://api.github.com/repos/octo-org/octo-repo/check-runs/399444496",
"labels": [
"self-hosted",
"foo",
"bar"
],
"runner_id": 1,
"runner_name": "my runner",
"runner_group_id": 2,
"runner_group_name": "my runner group",
"workflow_name": "CI",
"head_branch": "main"
}
下载工作流运行的作业日志
获取一个重定向 URL,用于下载工作流作业的纯文本日志文件。此链接在 1 分钟后过期。在响应头中查找 `Location:` 以找到下载的 URL。
任何拥有仓库读取权限的人都可以使用此端点。
如果仓库是私有的,OAuth 令牌和个人访问令牌(经典)需要 `repo` 范围才能使用此端点。
用于“下载工作流程运行的作业日志”的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- “操作”仓库权限(读取)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。
“下载工作流程运行的作业日志”的参数
名称,类型,描述 |
---|
accept string 建议设置为 `application/vnd.github+json`。 |
名称,类型,描述 |
---|
owner string 必需仓库的帐户所有者。名称不区分大小写。 |
repo string 必需仓库的名称,不包含 `.git` 扩展名。名称不区分大小写。 |
job_id integer 必需作业的唯一标识符。 |
“下载工作流程运行的作业日志”的 HTTP 响应状态码
状态代码 | 描述 |
---|---|
302 | 已找到 |
“下载工作流程运行的作业日志”的代码示例
请求示例
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/jobs/JOB_ID/logs
响应
状态:302
列出工作流程运行尝试的作业
列出特定工作流程运行尝试的作业。您可以使用参数缩小结果列表。有关使用参数的更多信息,请参阅 参数。
任何拥有仓库读取权限的人都可以使用此端点。
OAuth 应用令牌和个人访问令牌(经典)需要 repo
范围才能将此端点与私有存储库一起使用。
用于“列出工作流程运行尝试的作业”的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- “操作”仓库权限(读取)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。
“列出工作流程运行尝试的作业”的参数
名称,类型,描述 |
---|
accept string 建议设置为 `application/vnd.github+json`。 |
名称,类型,描述 |
---|
owner string 必需仓库的帐户所有者。名称不区分大小写。 |
repo string 必需仓库的名称,不包含 `.git` 扩展名。名称不区分大小写。 |
run_id 整数 必需工作流程运行的唯一标识符。 |
attempt_number 整数 必需工作流程运行的尝试次数。 |
名称,类型,描述 |
---|
per_page 整数 每页的结果数量(最大 100)。有关更多信息,请参阅“在 REST API 中使用分页”。 默认: |
page 整数 要获取的结果的页码。有关更多信息,请参阅“在 REST API 中使用分页”。 默认: |
“列出工作流程运行尝试的作业”的 HTTP 响应状态码
状态代码 | 描述 |
---|---|
200 | OK |
404 | 资源未找到 |
“列出工作流程运行尝试的作业”的代码示例
请求示例
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/runs/RUN_ID/attempts/ATTEMPT_NUMBER/jobs
响应
状态:200
{
"total_count": 1,
"jobs": [
{
"id": 399444496,
"run_id": 29679449,
"run_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/29679449",
"node_id": "MDEyOldvcmtmbG93IEpvYjM5OTQ0NDQ5Ng==",
"head_sha": "f83a356604ae3c5d03e1b46ef4d1ca77d64a90b0",
"url": "https://api.github.com/repos/octo-org/octo-repo/actions/jobs/399444496",
"html_url": "https://github.com/octo-org/octo-repo/runs/29679449/jobs/399444496",
"status": "completed",
"conclusion": "success",
"started_at": "2020-01-20T17:42:40Z",
"completed_at": "2020-01-20T17:44:39Z",
"name": "build",
"steps": [
{
"name": "Set up job",
"status": "completed",
"conclusion": "success",
"number": 1,
"started_at": "2020-01-20T09:42:40.000-08:00",
"completed_at": "2020-01-20T09:42:41.000-08:00"
},
{
"name": "Run actions/checkout@v2",
"status": "completed",
"conclusion": "success",
"number": 2,
"started_at": "2020-01-20T09:42:41.000-08:00",
"completed_at": "2020-01-20T09:42:45.000-08:00"
},
{
"name": "Set up Ruby",
"status": "completed",
"conclusion": "success",
"number": 3,
"started_at": "2020-01-20T09:42:45.000-08:00",
"completed_at": "2020-01-20T09:42:45.000-08:00"
},
{
"name": "Run actions/cache@v3",
"status": "completed",
"conclusion": "success",
"number": 4,
"started_at": "2020-01-20T09:42:45.000-08:00",
"completed_at": "2020-01-20T09:42:48.000-08:00"
},
{
"name": "Install Bundler",
"status": "completed",
"conclusion": "success",
"number": 5,
"started_at": "2020-01-20T09:42:48.000-08:00",
"completed_at": "2020-01-20T09:42:52.000-08:00"
},
{
"name": "Install Gems",
"status": "completed",
"conclusion": "success",
"number": 6,
"started_at": "2020-01-20T09:42:52.000-08:00",
"completed_at": "2020-01-20T09:42:53.000-08:00"
},
{
"name": "Run Tests",
"status": "completed",
"conclusion": "success",
"number": 7,
"started_at": "2020-01-20T09:42:53.000-08:00",
"completed_at": "2020-01-20T09:42:59.000-08:00"
},
{
"name": "Deploy to Heroku",
"status": "completed",
"conclusion": "success",
"number": 8,
"started_at": "2020-01-20T09:42:59.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
},
{
"name": "Post actions/cache@v3",
"status": "completed",
"conclusion": "success",
"number": 16,
"started_at": "2020-01-20T09:44:39.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
},
{
"name": "Complete job",
"status": "completed",
"conclusion": "success",
"number": 17,
"started_at": "2020-01-20T09:44:39.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
}
],
"check_run_url": "https://api.github.com/repos/octo-org/octo-repo/check-runs/399444496",
"labels": [
"self-hosted",
"foo",
"bar"
],
"runner_id": 1,
"runner_name": "my runner",
"runner_group_id": 2,
"runner_group_name": "my runner group",
"workflow_name": "CI",
"head_branch": "main"
}
]
}
列出工作流程运行的作业
列出工作流程运行的作业。您可以使用参数缩小结果列表。有关使用参数的更多信息,请参阅 参数。
任何拥有仓库读取权限的人都可以使用此端点。
OAuth 应用令牌和个人访问令牌(经典)需要 repo
范围才能将此端点与私有存储库一起使用。
用于“列出工作流程运行的作业”的细粒度访问令牌
此端点适用于以下细粒度令牌类型
细粒度令牌必须具有以下权限集
- “操作”仓库权限(读取)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。
“列出工作流运行的作业”参数
名称,类型,描述 |
---|
accept string 建议设置为 `application/vnd.github+json`。 |
名称,类型,描述 |
---|
owner string 必需仓库的帐户所有者。名称不区分大小写。 |
repo string 必需仓库的名称,不包含 `.git` 扩展名。名称不区分大小写。 |
run_id 整数 必需工作流程运行的唯一标识符。 |
名称,类型,描述 |
---|
filter 字符串 根据作业的 默认: 可以是以下之一: |
per_page 整数 每页的结果数量(最大 100)。有关更多信息,请参阅“在 REST API 中使用分页”。 默认: |
page 整数 要获取的结果的页码。有关更多信息,请参阅“在 REST API 中使用分页”。 默认: |
“列出工作流运行的作业”的 HTTP 响应状态码
状态代码 | 描述 |
---|---|
200 | OK |
“列出工作流运行的作业”的代码示例
请求示例
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/runs/RUN_ID/jobs
响应
状态:200
{
"total_count": 1,
"jobs": [
{
"id": 399444496,
"run_id": 29679449,
"run_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/29679449",
"node_id": "MDEyOldvcmtmbG93IEpvYjM5OTQ0NDQ5Ng==",
"head_sha": "f83a356604ae3c5d03e1b46ef4d1ca77d64a90b0",
"url": "https://api.github.com/repos/octo-org/octo-repo/actions/jobs/399444496",
"html_url": "https://github.com/octo-org/octo-repo/runs/29679449/jobs/399444496",
"status": "completed",
"conclusion": "success",
"started_at": "2020-01-20T17:42:40Z",
"completed_at": "2020-01-20T17:44:39Z",
"name": "build",
"steps": [
{
"name": "Set up job",
"status": "completed",
"conclusion": "success",
"number": 1,
"started_at": "2020-01-20T09:42:40.000-08:00",
"completed_at": "2020-01-20T09:42:41.000-08:00"
},
{
"name": "Run actions/checkout@v2",
"status": "completed",
"conclusion": "success",
"number": 2,
"started_at": "2020-01-20T09:42:41.000-08:00",
"completed_at": "2020-01-20T09:42:45.000-08:00"
},
{
"name": "Set up Ruby",
"status": "completed",
"conclusion": "success",
"number": 3,
"started_at": "2020-01-20T09:42:45.000-08:00",
"completed_at": "2020-01-20T09:42:45.000-08:00"
},
{
"name": "Run actions/cache@v3",
"status": "completed",
"conclusion": "success",
"number": 4,
"started_at": "2020-01-20T09:42:45.000-08:00",
"completed_at": "2020-01-20T09:42:48.000-08:00"
},
{
"name": "Install Bundler",
"status": "completed",
"conclusion": "success",
"number": 5,
"started_at": "2020-01-20T09:42:48.000-08:00",
"completed_at": "2020-01-20T09:42:52.000-08:00"
},
{
"name": "Install Gems",
"status": "completed",
"conclusion": "success",
"number": 6,
"started_at": "2020-01-20T09:42:52.000-08:00",
"completed_at": "2020-01-20T09:42:53.000-08:00"
},
{
"name": "Run Tests",
"status": "completed",
"conclusion": "success",
"number": 7,
"started_at": "2020-01-20T09:42:53.000-08:00",
"completed_at": "2020-01-20T09:42:59.000-08:00"
},
{
"name": "Deploy to Heroku",
"status": "completed",
"conclusion": "success",
"number": 8,
"started_at": "2020-01-20T09:42:59.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
},
{
"name": "Post actions/cache@v3",
"status": "completed",
"conclusion": "success",
"number": 16,
"started_at": "2020-01-20T09:44:39.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
},
{
"name": "Complete job",
"status": "completed",
"conclusion": "success",
"number": 17,
"started_at": "2020-01-20T09:44:39.000-08:00",
"completed_at": "2020-01-20T09:44:39.000-08:00"
}
],
"check_run_url": "https://api.github.com/repos/octo-org/octo-repo/check-runs/399444496",
"labels": [
"self-hosted",
"foo",
"bar"
],
"runner_id": 1,
"runner_name": "my runner",
"runner_group_id": 2,
"runner_group_name": "my runner group",
"workflow_name": "CI",
"head_branch": "main"
}
]
}