GitLab Integration Setup Guide

GitLab Integration Setup Guide

This guide walks you through connecting Lathe Studio to GitLab for CI/CD pipeline integration.


Prerequisites#

  • GitLab account (GitLab.com or self-hosted)
  • GitLab project with CI/CD pipelines
  • Project admin access in Lathe Studio

Overview#

The GitLab integration enables:

  • CI/CD Webhooks: Automatically create builds when GitLab pipelines complete
  • Pipeline Visibility: View pipeline status in Lathe Studio
  • Merge Request Integration: Display test results in MRs

Connecting GitLab#

Step 1: Create an API Key

  1. Go to Settings > Organization > API Keys
  2. Click Create API Key
  3. Give it a name (e.g., "GitLab CI")
  4. Select scopes:
    • builds:read - View builds
    • builds:create - Create new builds
  5. Copy the generated key (shown only once)

Step 2: Configure GitLab Webhook

  1. In GitLab, go to your project
  2. Navigate to Settings > Webhooks
  3. Configure:
    • URL: https://lathestudio.dev/api/webhooks/gitlab
    • Secret Token: Your API key (optional, for verification)
  4. Trigger events: Select "Pipeline events"
  5. SSL verification: Enable (recommended)
  6. Click Add webhook

Step 3: Test the Integration

  1. Trigger a pipeline in GitLab
  2. Go to Releases page in Lathe Studio
  3. You should see the build in the Build Queue section
  4. Assign it to a release

Authentication Methods#

GitLab sends the secret token in the X-Gitlab-Token header. Add your API key there:

  • Secret Token: pt_live_xxxxxxxxxxxxxxxx

Method 2: Authorization Header

Configure a custom header:

  • Name: Authorization
  • Value: Bearer pt_live_xxxxxxxxxxxxxxxx

Method 3: Organization ID

Include your organization ID:

  • Name: X-Pt-Org-Id
  • Value: your-org-uuid

How It Works#

  1. Pipeline Completes → GitLab sends webhook to /api/webhooks/gitlab
  2. Authentication → Webhook verifies API key or org ID
  3. Project Matching → System tries to match project URL to a Lathe Studio project
  4. Queue or Create:
    • If project + active release found → Build created directly
    • If project found but no release → Queued for release assignment
    • If no project match → Queued for project + release assignment
  5. Assignment → User assigns queued builds via Releases page

Build Queue UI#

The Build Queue appears on the Releases page when there are pending builds:

  • Shows build name, source (GitLab), project, commit/branch
  • Assign to Release: Select an active release for the project
  • Select Project: Navigate to projects if project not auto-detected
  • Reject: Remove build from queue (no build created)

GitLab CI Example#

Add this to your .gitlab-ci.yml:

stages:
  - test
  - report

test:
  stage: test
  script:
    - npm test
  artifacts:
    reports:
      junit: test-results.xml

notify-lathe-studio:
  stage: report
  only:
    - main
    - develop
  script:
    - |
      curl -X POST https://lathestudio.dev/api/v1/results/ingest \
        -H "Authorization: Bearer $PT_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "build_name": "Pipeline $CI_PIPELINE_ID",
          "branch": "'"$CI_COMMIT_BRANCH"'",
          "commit_sha": "'"$CI_COMMIT_SHA"'",
          "test_results": [...]
        }'

Self-Hosted GitLab#

For GitLab self-hosted instances:

  1. Ensure your instance is accessible from the internet
  2. Use the same webhook URL: https://lathestudio.dev/api/webhooks/gitlab
  3. Configure SSL certificates properly
  4. Allowlist Lathe Studio IP addresses if using a firewall:
    • Contact support for current IP ranges

Troubleshooting#

Builds not appearing

  1. Check webhook delivery in GitLab (Settings > Webhooks > Recent Deliveries)
  2. Verify API key is not expired or revoked
  3. Ensure "Pipeline events" is selected in webhook settings
  4. Check that the project URL matches your Lathe Studio project settings

Wrong project assigned

The system matches by:

  1. Project URL (exact match)
  2. Project name (partial match)
  3. Repository path

You can manually assign to the correct project from the queue.

Rate limiting

API keys are limited to 60 requests per minute by default. Contact support to increase limits.

Self-hosted SSL issues

If using self-signed certificates:

  1. Use valid SSL certificates (Let's Encrypt recommended)
  2. Or disable SSL verification in webhook settings (not recommended for production)

Security#

  • API keys are hashed using SHA-256 before storage
  • Only the first 12 characters are stored for identification
  • Keys can be revoked at any time
  • GitLab secret tokens are verified on each request
  • All webhook communications use HTTPS

Unlinking GitLab#

To disconnect:

  1. Go to your GitLab project
  2. Navigate to Settings > Webhooks
  3. Find the Lathe Studio webhook
  4. Click Delete

Note: Previously created builds remain in Lathe Studio. New builds will not be created until reconnected.


Advanced Configuration#

Pipeline Filtering

Configure which pipelines trigger builds in Project Settings > CI/CD:

  • Include: main, develop, release/*
  • Exclude: dependabot/*, draft/*

Custom Build Metadata

Add pipeline variables to customize build information:

  • PT_BUILD_NAME: Override default build name
  • PT_RELEASE_TAG: Associate with a specific release

For additional help, contact support.