我有一个带有多个独立应用程序的 Git 存储库,以多种语言(又名monorepo)开发。
在这个存储库中,我可以使用多个作为连续模板来并行构建我的所有项目吗?
我有一个带有多个独立应用程序的 Git 存储库,以多种语言(又名monorepo)开发。
在这个存储库中,我可以使用多个作为连续模板来并行构建我的所有项目吗?
你当然可以。
一些构建模板还支持并行矩阵作业,允许您使用同一模板处理多个项目。
假设 GitLab 项目由以下部分组成:
app/
:一个前端应用程序,用 Angular 开发users-srv/
:第一个后端服务,在 Node 中开发,打包为 Docker 映像orders-srv/
:第二个后端服务,在 Node 中开发,打包为 Docker 镜像tools/
: 一些工具,用 Python 开发您的.gitlab-ci.yml
文件应如下所示:
# included templates
include:
# Angular template
- project: "to-be-continuous/angular"
ref: "1.2.0"
file: "templates/gitlab-ci-angular.yml"
# Node.js template
- project: "to-be-continuous/node"
ref: "1.2.0"
file: "templates/gitlab-ci-node.yml"
# Python template
- project: "to-be-continuous/python"
ref: "1.2.0"
file: "templates/gitlab-ci-python.yml"
# Docker template
- project: "to-be-continuous/docker"
ref: "1.2.0"
file: "templates/gitlab-ci-docker.yml"
# variables
variables:
# path of the Angular project
NG_WORKSPACE_DIR: "app"
# path of the Python project
PYTHON_PROJECT_DIR: "tools"
# parallel matrix jobs for Node template
.node-base:
parallel:
matrix:
# path of the "users-srv" Node project
- NODE_PROJECT_DIR: "users-srv"
# path of the "orders-srv" Node project
- NODE_PROJECT_DIR: "orders-srv"
# parallel matrix jobs for Docker template
.docker-base:
parallel:
matrix:
# Docker config for project "users-srv"
- DOCKER_FILE: "users-srv/Dockerfile"
DOCKER_SNAPSHOT_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/users-srv/snapshot:$CI_COMMIT_REF_SLUG"
DOCKER_RELEASE_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/users-srv:$CI_COMMIT_REF_NAME"
# Docker config for project "orders-srv"
- DOCKER_FILE: "orders-srv/Dockerfile"
DOCKER_SNAPSHOT_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/orders-srv/snapshot:$CI_COMMIT_REF_SLUG"
DOCKER_RELEASE_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/orders-srv:$CI_COMMIT_REF_NAME"
# your pipeline stages
stages:
- build
- test
- package-build
- package-test
- deploy
- acceptance
- publish
- production