上传和下载制品
本文档介绍如何通过 upload-artifact 和 download-artifact 插件在 Job 之间传递构建产物和文件。
当你需要在 job 之间传递构建产物(如编译结果、测试报告、打包文件等)时。
前提条件
- 已确认使用的 artifact 插件版本。
- 已确认制品大小不超过限制。
快速示例
name: build-and-package
on:
push:
branches:
- main
jobs:
build:
name: 构建
runs-on: [ubuntu-latest, x64, small]
steps:
- name: Checkout source code
uses: checkout
- name: Build
run: |
mkdir -p dist
echo "hello" > dist/app.txt
- name: Upload artifact
uses: upload-artifact
with:
name: app-dist
path: dist/
deploy:
name: 部署
runs-on: [ubuntu-latest, x64, small]
needs: build
steps:
- name: Download artifact
uses: download-artifact
with:
name: app-dist
path: dist/
- name: Verify artifact
run: cat dist/app.txt
配置说明
上传制品
steps:
- name: Upload artifact
uses: upload-artifact
with:
name: app-dist
path: dist/
| 参数 | 必填 | 说明 |
|---|---|---|
name | 是 | 制品名称,同一 workflow 中唯一 |
path | 是 | 上传路径,支持文件和目录,支持 glob 模式 |
上传多个路径:
steps:
- name: Upload multiple paths
uses: upload-artifact
with:
name: build-output
path: |
dist/
reports/
coverage/
下载制品
steps:
- name: Download artifact
uses: download-artifact
with:
name: app-dist
path: dist/
| 参数 | 必填 | 说明 |
|---|---|---|
name | 是 | 要下载的制品名称 |
path | 否 | 下载目标路径,默认为当前工作目录 |
下载当前 workflow 所有制品:
steps:
- name: Download all artifacts
uses: download-artifact
with:
path: artifacts/