1. 什么是 .gitlab-ci.yml
项目的构建流程是由项目根目录的 .gitlab-ci.yml
文件控制的。
在对代码库进行任何推送时,GitLab都会查找该项目下.gitlab-ci.yml 文件,并根据该文件的内容在Runners上启动作业。完成一些列的操作。
在定义作业(任务)时,每个作业的名称要相对唯一,但是,一些默认保留关键字是不可以作为作业名字使用的:
image
services
stages
types
before_script
after_script
variables
cache
include
2. 配置参数讲解(我用到的)
此处的参数讲解,只会说明我实际中用到的参数,关于其他参数,请详细查阅官方文档。
a. services:使用docker服务镜像,使用方式:services:name
services: - docker:20.10.6-dind
b. variables:全局参数配置:
variables: MAVEN_OPTS: "-Dmaven.repo.local=/root/.m2/repository"
c. stages: 定义整个过程的阶段:
stages: - build jar - build and push docker image - deploy
d. cache:缓存配置:key->为缓存的标识,paths,缓存内容;
cache: &global_cache key: ${CI_COMMIT_REF_NAME} paths: - .m2/repository/ - target/lib/*.jar
e. before_script:执行任务之前执行的shell脚本;
f. script:runner执行的shell脚本;
g. after_script:执行任务完成执行的shell脚本;
h. image:任务过程中使用的docker镜像;
此外,其他的参数,请查阅官方文档:
https://docs.gitlab.com/ee/ci/yaml/gitlab_ci_yaml.html
你的努力,终将成为你最有力的资本!