使用极狐GitLab 作为微服务

许多应用程序需要访问 JSON API,因此应用程序测试可能也需要访问 API。以下示例展示了如何使用极狐GitLab 作为微服务,来为测试提供对 GitLab API 的访问权限。

  1. 使用 Docker 或 Kubernetes executor 配置 runner。
  2. .gitlab-ci.yml 中添加:

    services:
      - name: gitlab/gitlab-ce:latest
        alias: gitlab
    
    variables:
      GITLAB_HTTPS: "false"             # ensure that plain http works
      GITLAB_ROOT_PASSWORD: "password"  # to access the api with user root:password
    
noteGitLab UI 中设置的变量不会传递到服务容器。了解更多

然后,.gitlab-ci.yml 文件中 script 部分中的命令可以访问 http://gitlab/api/v4 上的 API。

有关为何将 gitlab 用于 Host 的更多信息,请参阅服务如何链接到作业

gitlab 镜像可以接受环境变量。有关更多详细信息,请参阅 Omnibus 文档