Github Actions E06产出物

前言

大多数时候,workflow的产出物都会直接传到对应的某些仓库,比如docker image会送到docker hub这种仓库存储。这种时候是不需要在workflow再额外的管理产出物,但也不能全盘否定;有时候我们没有一个方便的地方去存储某些形式的文件等,就需要我们有类似jenkins archiveArtifacts 功能。但github actions能做的会更多,请期待。

1. 关于artifacts

构件是指在工作流程运行过程中产生的文件或文件集。
GitHub 提供两项可用于上传和下载构建构件的操作。 上传到工作流程运行的文件将使用 .zip 格式存档。 更多信息请参阅 action/upload-artifactdownload-artifact 操作。

这些是您可能想要上传的一些常见构建和测试输出构件:

  • 日志文件和核心转储文件
  • 测试结果、失败和屏幕截图
  • 二进制或存档文件
  • 压力测试性能输出和代码覆盖结果

当作业完成时,运行程序将终止并删除虚拟环境的实例。

2. 上传

常见的场景: 一个java程序的产出物是一个jar包,在构建之后需要得到这个jar用于其他环境部署。

依旧用 api-test-demo 这个仓库做演示,主要分为以下个步骤:

  • 1.下载代码;
  • 2.构建jar包(存放于指定到路径build/libs/api-demo-0.0.1-SNAPSHOT.jar);
  • 3.上传jar包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
name: my workflow demo 

on:
push:
branches:
- master

jobs:
artifacts_demo_job:
name: job1
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Build jar
run: |
pwd && ls -l
./gradlew -x jar build
ls -l build/libs/api-demo-0.0.1-SNAPSHOT.jar
- name: Archive SNAPSHOT.jar
uses: actions/upload-artifact@v1
with:
name: api_snapshot_jar
path: build/libs/api-demo-0.0.1-SNAPSHOT.jar

github actions 工作流的产出物都放在哪里的,保留多久

3. 下载

步骤官方说明如下:

  • 1.On GitHub, navigate to the main page of the repository.
  • 2.Under your repository name, click Actions.
  • 3.In the left sidebar, click the workflow you want to see.
  • 4.Under “Workflow runs”, click the name of the run you want to see.
  • 5.To download artifacts, use the Artifacts drop-down menu, and select the artifact you want to download.
  • 6.To delete artifacts, use the Artifacts drop-down menu, and click .

注意事项:

  • 保留90天
  • 一旦删除某一个构件,无法恢复

4. 在工作流程中作业之间传递数据

https://help.github.com/cn/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts#passing-data-between-jobs-in-a-workflow

由于同一个workflow的多个job分别运行在不同的虚拟主机上,下面示例工作流程说明如何在相同工作流程中的任务之间传递数据。关键词 need 用来确保job按顺序运行.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
name: Share data between jobs

on: [push]

jobs:
job_1:
name: Add 3 and 7
runs-on: ubuntu-latest
steps:
- shell: bash
run: |
expr 3 + 7 > math-homework.txt
- name: Upload math result for job 1
uses: actions/upload-artifact@v1
with:
name: homework
path: math-homework.txt

job_2:
name: Multiply by 9
needs: job_1
runs-on: windows-latest
steps:
- name: Download math result for job 1
uses: actions/download-artifact@v1
with:
name: homework
- shell: bash
run: |
value=`cat homework/math-homework.txt`
expr $value \* 9 > homework/math-homework.txt
- name: Upload math result for job 2
uses: actions/upload-artifact@v1
with:
name: homework
path: homework/math-homework.txt

job_3:
name: Display results
needs: job_2
runs-on: macOS-latest
steps:
- name: Download math result for job 2
uses: actions/download-artifact@v1
with:
name: homework
- name: Print the final result
shell: bash
run: |
value=`cat homework/math-homework.txt`
echo The result is $value

More Ref:

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~