2021-04-15 14:09:01 -04:00
---
stage: Verify
group: Runner
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
type: reference
---
2021-04-19 20:09:27 -04:00
# Use GitLab as a microservice
2021-04-15 14:09:01 -04:00
2021-04-19 20:09:27 -04:00
Many applications need to access JSON APIs, so application tests might need access
to APIs too. The following example shows how to use GitLab as a microservice to give
tests access to the GitLab API.
2021-04-15 14:09:01 -04:00
2021-06-28 08:38:12 -04:00
1. Configure a [runner ](../runners/index.md ) with the Docker or Kubernetes executor.
2021-04-19 20:09:27 -04:00
1. In your `.gitlab-ci.yml` add:
2021-04-15 14:09:01 -04:00
2021-04-19 20:09:27 -04:00
```yaml
services:
- name: gitlab/gitlab-ce:latest
alias: gitlab
2021-04-15 14:09:01 -04:00
2021-04-19 20:09:27 -04:00
variables:
GITLAB_HTTPS: "false" # ensure that plain http works
GITLAB_ROOT_PASSWORD: "password" # to access the api with user root:password
```
2021-04-15 14:09:01 -04:00
2021-04-19 20:09:27 -04:00
1. To set values for the `GITLAB_HTTPS` and `GITLAB_ROOT_PASSWORD` ,
2021-06-28 11:08:03 -04:00
[assign them to a variable in the user interface ](../variables/index.md#add-a-cicd-variable-to-a-project ).
2021-04-19 20:09:27 -04:00
Then assign that variable to the corresponding variable in your
`.gitlab-ci.yml` file.
2021-04-22 23:09:40 -04:00
2021-04-19 20:09:27 -04:00
Then, commands in `script:` sections in your `.gitlab-ci.yml` file can access the API at `http://gitlab/api/v4` .
2021-04-15 14:09:01 -04:00
2021-04-19 20:09:27 -04:00
For more information about why `gitlab` is used for the `Host` , see
2021-04-15 14:09:01 -04:00
[How services are linked to the job ](../docker/using_docker_images.md#extended-docker-configuration-options ).
You can also use any other Docker image available on [Docker Hub ](https://hub.docker.com/u/gitlab ).
2021-04-19 20:09:27 -04:00
The `gitlab` image can accept environment variables. For more details,
2021-06-21 05:10:07 -04:00
see the [Omnibus documentation ](../../install/index.md ).