| title | Linking code from GitLab |
|---|---|
| sidebarTitle | GitLab |
| icon | GitLab |
import GitLabSchema from '/snippets/schemas/v3/gitlab.schema.mdx'
Sourcebot can sync code from GitLab.com, Self Managed (CE & EE), and Dedicated.
```json { "type": "gitlab", "projects": [ "my-group/foo", "my-group/subgroup/bar" ] } ``` ```json { "type": "gitlab", "groups": [ "my-group", "my-other-group/sub-group" ] } ``` This option is ignored if `url` is unset. See [connecting to a custom gitlab host](/docs/connections/gitlab#connecting-to-a-custom-gitlab-host). ```json { "type": "gitlab", "url": "https://gitlab.example.com", // Index all projects in this self-managed instance "all": true } ``` ```json { "type": "gitlab", "users": [ "user-1", "user-2" ] } ``` ```json { "type": "gitlab", // Sync all projects in `my-group` that have a topic that... "groups": [ "my-group" ], // ...match one of these glob patterns. "topics": [ "test-*", "ci-*", "k8s" ] } ```
</Accordion>
<Accordion title="Exclude projects from syncing">
```json
{
"type": "gitlab",
// Include all projects in these groups...
"groups": [
"my-group",
"my-other-group/sub-group"
]
// ...except:
"exclude": {
// projects that are archived
"archived": true,
// projects that are forks
"forks": true,
// projects that match these glob patterns
"projects": [
"my-group/foo/**",
"my-group/bar/**",
"my-other-group/sub-group/specific-project"
],
// repos with topics that match these glob patterns
"topics": [
"test-*",
"ci"
]
}
}
```
</Accordion>
In order to index private projects, you'll need to generate a GitLab Personal Access Token (PAT). Create a new PAT here and make sure you select the read_api scope:
Next, provide the PAT via the token property, either as an environment variable or a secret:
1. Add the `token` property to your connection config:
```json
{
"type": "gitlab",
"token": {
// note: this env var can be named anything. It
// doesn't need to be `GITLAB_TOKEN`.
"env": "GITLAB_TOKEN"
}
// .. rest of config ..
}
```
2. Pass this environment variable each time you run Sourcebot:
```bash
docker run \
-e GITLAB_TOKEN=<PAT> \
/* additional args */ \
ghcr.io/sourcebot-dev/sourcebot:latest
```
</Tab>
<Tab title="Secret">
<Note>Secrets are only supported when [authentication](/docs/configuration/auth/overview) is enabled.</Note>
1. Navigate to **Secrets** in settings and create a new secret with your PAT:

2. Add the `token` property to your connection config:
```json
{
"type": "gitlab",
"token": {
"secret": "mysecret"
}
// .. rest of config ..
}
```
</Tab>
To connect to a GitLab host other than gitlab.com, provide the url property to your config:
{
"type": "gitlab",
"url": "https://gitlab.example.com"
// .. rest of config ..
}- If you're seeing errors like
GitbeakerTimeoutError: Query timeout was reachedwhen syncing a large number of projects, you can increase the client's timeout by setting theGITLAB_CLIENT_QUERY_TIMEOUT_SECONDSenvironment variable. #162
