Help us learn about your current experience with the documentation. Take the survey.
将 GitLab 用作微服务
- 版本:Free, Premium, Ultimate
- 产品:GitLab.com, GitLab Self-Managed, GitLab Dedicated
许多应用程序需要访问 JSON API,因此应用程序测试也可能需要访问 API。下面的示例展示了如何将 GitLab 用作微服务,以便为测试提供访问 GitLab API 的能力。
-
配置一个使用 Docker 或 Kubernetes executor 的 runner。
-
在你的
.gitlab-ci.yml文件中添加:services: - name: gitlab/gitlab-ce:latest alias: gitlab variables: GITLAB_HTTPS: "false" # 确保普通的 http 可以工作 GITLAB_ROOT_PASSWORD: "password" # 以便使用 root:password 用户访问 api
在 GitLab UI 中设置的变量不会传递给服务容器。 更多信息,请参阅 GitLab CI/CD variables。
然后,.gitlab-ci.yml 文件中 script 部分的命令便可以在 http://gitlab/api/v4 访问该 API。
关于为何使用 gitlab 作为 Host 的更多信息,请参阅 服务如何链接到作业。
你也可以使用 Docker Hub 上提供的任何其他 Docker 镜像。
gitlab 镜像可以接受环境变量。更多详情,请参阅 Linux 软件包文档。