1. 工件配置
默认情况下,所有GitLab安装中均启用此功能。
(1) 禁用工件
$ vim /etc/gitlab/gitlab.rb
...
gitlab_rails['artifacts_enabled'] = false
...
(2)存储工件
默认情况下,工件存储在本地目录:/var/opt/gitlab/gitlab-rails/shared/artifacts
,也可修改存储目录。
gitlab_rails['artifacts_path'] = "/mnt/storage/artifacts"
如果您不想使用安装了GitLab的本地磁盘来存储工件,则可以使用AWS S3之类的对象存储。参考:https://docs.gitlab.com/12.10/ee/administration/job_artifacts.html#using-object-storage
2. .gitlab.yml 配置工件
gitlab.yml 中,使用 artifacts 参数进行工件的配置。
//示例
variables:
MAVEN_OPTS: "-Dmaven.repo.local=.m2"
stages:
- test
- build
test:
stage: test
image: harbor.xiodi.cn/tools/openjdk:11.0.6
tags:
- docker
- host20133-docker
script:
- chmod +x ./mvnw && ./mvnw test
cache:
key: maven-repo-cache
paths:
- .m2
build:
stage: build
image: harbor.xiodi.cn/tools/openjdk:11.0.6
tags:
- docker
- host20133-docker
script:
- chmod +x ./mvnw && ./mvnw package
cache:
key: maven-repo-cache
paths:
- .m2
artifacts:
paths:
- target/*.jar
expire_in: 1 week
//示例2,等同于示例1
stages:
- build
build:
stage: build
image: harbor.xiodi.cn/tools/openjdk:11.0.6
tags:
- docker
- host20133-docker
script:
- mkdir artifacts
- cp target/*.jar artifacts/
artifacts:
paths:
- artifacts/
expire_in: 1 week
这种方式的好处是,存储更加简洁。
3. 工件的操作
3.1 浏览工件
当作业完成后,就会有以下的页面。
- 保持:当您设置了有效日期后,会有该选项,如果点击
保持
,则会取消有效日期
- 浏览:用于 web查看工件详细信息。
3.2 下载工件
下载的方式有两种:
- GitLab UI 页面
- GitLab URL
(1) GitLab UI 页面
可以下载的地方有很多,比如
//job页面
//流水线页面
(2)GitLab URL
//URL 结构,下载整个工件
https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/download?job=<job_name>
//URL 结构,下个单个文件
https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/raw/<path_to_file>?job=<job_name>
//例子
https://gitlabtest.xiodi.cn/edu-java-demo/edu-java-spring/-/jobs/artifacts/feature-1/download?job=build
https://gitlabtest.xiodi.cn/edu-java-demo/edu-java-spring/-/jobs/33/artifacts/raw/artifacts/demo-0.0.1-SNAPSHOT.jar
3.3 删除工件
删除作业的同时,也将删除作业的工件和跟踪。
[info]可以通过 du -sh 查看存储目录大小就可以看出删除了工件。