30 秒接入¶
第一步:添加配置¶
在项目根目录创建 .gitlab-ci.yml:
include:
- remote: 'https://raw.githubusercontent.com/cdryzun/gitlab-ci-templates/open/templates/Auto-DevOps.gitlab-ci.yml'
第二步:推送代码¶
流水线自动触发。模板会:
- 自动检测项目类型(通过
pom.xml/package.json/requirements.txt/go.mod) - 自动选择构建镜像和构建命令
- 构建 Docker 镜像并推送到 Registry
- 运行单元测试
常见覆盖配置¶
Java 项目¶
include:
- remote: 'https://raw.githubusercontent.com/cdryzun/gitlab-ci-templates/open/templates/Auto-DevOps.gitlab-ci.yml'
variables:
BUILD_SHELL: "mvn clean package -DskipTests"
DOCKERFILE_BUILD_JDK_VERSION: "17"
前端项目(React / Vue)¶
include:
- remote: 'https://raw.githubusercontent.com/cdryzun/gitlab-ci-templates/open/templates/Auto-DevOps.gitlab-ci.yml'
variables:
BUILD_SHELL: "pnpm run build"
PACKAGE_MANAGER: "pnpm"
纯库项目(不构建镜像)¶
include:
- remote: 'https://raw.githubusercontent.com/cdryzun/gitlab-ci-templates/open/templates/Auto-DevOps.gitlab-ci.yml'
variables:
DOCKER_IMAGE_BUILD: "false"
开启 GitOps 部署¶
在 GitLab CI/CD Settings > Variables 中配置 DEPLOY_REPO(Helm charts 仓库地址),然后在 .gitlab-ci.yml 中添加:
variables:
DEPLOY_REPO_PROJ: "my-service"
DEPLOY_VALUE_FILE: "values-dev.yaml"
DEPLOY_REPO_YAML_TAG: ".image.tag"
更多配置项见 变量参考。