Skip to main content
OpenSRE queries GitLab to retrieve recent commits, merge requests, failed pipelines, and file contents — helping trace which code change or deployment triggered an alert.

Prerequisites

  • GitLab account (GitLab.com or self-hosted)
  • Personal access token or group/project access token

Setup

Option 1: Interactive CLI

opensre integrations setup
Select GitLab when prompted and provide your access token.

Option 2: Environment variables

Add to your .env:
GITLAB_ACCESS_TOKEN=glpat-your-token
GITLAB_BASE_URL=https://gitlab.com/api/v4   # optional, for self-hosted
VariableDefaultDescription
GITLAB_ACCESS_TOKENRequired. GitLab personal or project access token
GITLAB_BASE_URLhttps://gitlab.com/api/v4Override for self-hosted GitLab

Option 3: Persistent store

{
  "version": 1,
  "integrations": [
    {
      "id": "gitlab-prod",
      "service": "gitlab",
      "status": "active",
      "credentials": {
        "url": "https://gitlab.com/api/v4",
        "access_token": "glpat-your-token"
      }
    }
  ]
}

Creating a personal access token

  1. In GitLab, go to User SettingsAccess Tokens
  2. Click Add new token
  3. Enable the following scopes: read_api, read_repository
  4. Set an expiry and click Create personal access token
  5. Copy the token
For self-hosted GitLab, set GITLAB_BASE_URL=https://gitlab.example.com/api/v4.

Verify

opensre integrations verify --service gitlab
Expected output:
Service: gitlab
Status: passed
Detail: GitLab connectivity successful. Authenticated as @your-username

Troubleshooting

SymptomFix
401 UnauthorizedCheck that the token is valid and has read_api scope
404 Not FoundVerify the project ID and that the token has access to that project
Connection refusedCheck GITLAB_BASE_URL for self-hosted instances
Token expiredRotate the access token in GitLab settings

Security best practices

  • Use a read-only token with only read_api and read_repository scopes.
  • Prefer project access tokens scoped to the repositories OpenSRE needs.
  • Store the token in .env, not in source code.