前置步骤:
- Docker 版 DevOps GitLab CICD 实践1——GitLab 部署
- Docker 版 DevOps GitLab CICD 实践2——Runner 部署
官方文档
编写结构类似Jenkins pineline流水线
GitLab CI/CD Pipeline Configuration Reference
GitLab CI/CD Pipeline Configuration Reference
GitLab CI/CD pipelines are configured using a YAML file called
.gitlab-ci.yml
within each project.The
.gitlab-ci.yml
file defines the structure and order of the pipelines and determines:
- What to execute using GitLab Runner .
- What decisions to make when specific conditions are encountered. For example, when a process succeeds or fails.
This topic covers CI/CD pipeline configuration. For other CI/CD configuration information, see:
- GitLab CI/CD Variables , for configuring the environment the pipelines run in.
- GitLab Runner advanced configuration , for configuring GitLab Runner.
We have complete examples of configuring pipelines:
- For a quick introduction to GitLab CI, follow our quick start guide .
- For a collection of examples, see GitLab CI/CD Examples .
- To see a large
.gitlab-ci.yml
file used in an enterprise, see the.gitlab-ci.yml
file forgitlab-ce
.
目标
- maven项目自动打包
-
自动测试 - 自动镜像构建并上传
官方参数表列出了作业的可用参数:
关键词 | 描述 |
---|---|
script
|
由Runner执行的Shell脚本。 |
image
|
使用泊坞窗图像。也可用:
image:name
和
image:entrypoint
。
|
services
|
使用docker services图像。也可用:
services:name
,
services:alias
,
services:entrypoint
,和
services:command
。
|
before_script
|
覆盖在作业之前执行的一组命令。 |
after_script
|
覆盖作业后执行的一组命令。 |
stages
|
定义管道中的阶段。 |
stage
|
定义作业阶段(默认值:)
test
。
|
only
|
创建作业时限制。也可用:
only:refs
,
only:kubernetes
,
only:variables
,和
only:changes
。
|
except
|
在未创建作业时限制。也可用:
except:refs
,
except:kubernetes
,
except:variables
,和
except:changes
。
|
tags
|
用于选择Runner的标签列表。 |
allow_failure
|
让工作失败。失败的作业无助于提交状态。 |
when
|
什么时候开始工作。也可用:
when:manual
和
when:delayed
。
|
environment
|
作业部署到的环境的名称。也可用:
environment:name
,
environment:url
,
environment:on_stop
,和
environment:action
。
|
cache
|
后续运行之间应缓存的文件列表。也可用:
cache:paths
,
cache:key
,
cache:untracked
,和
cache:policy
。
|
artifacts
|
成功附加到作业的文件和目录列表。也可用:
artifacts:paths
,
artifacts:name
,
artifacts:untracked
,
artifacts:when
,
artifacts:expire_in
,
artifacts:reports
,和
artifacts:reports:junit
。 在GitLab
企业版
,这些都是可供选择:
artifacts:reports:codequality
,
artifacts:reports:sast
,
artifacts:reports:dependency_scanning
,
artifacts:reports:container_scanning
,
artifacts:reports:dast
,
artifacts:reports:license_management
,和
artifacts:reports:performance
。
|
dependencies
|
作业所依赖的其他作业,以便您可以在它们之间传递工件。 |
coverage
|
给定作业的代码覆盖率设置。 |
retry
|
在发生故障的情况下,可以自动重试作业的次数和次数。 |
parallel
|
应该并行运行多少个作业实例。 |
trigger
|
定义下游管道触发器。 |
include
|
允许此作业包含外部YAML文件。也可用:
include:local
,
include:file
,
include:template
,和
include:remote
。
|
extends
|
此作业将继承的配置条目。 |
pages
|
上传作业结果以用于GitLab Pages。 |
variables
|
在作业级别定义作业变量。 |
注:
参数
types
和
type
被
弃用
。