GitLab CI
This guide walks you through setting up Spekra in your GitLab CI/CD pipeline.
Prerequisites
- A GitLab repository with Playwright or Jest tests
- A Spekra account and API key
Setup Steps
1. Add Your API Key as a Variable
- Go to your project in GitLab
- Navigate to Settings → CI/CD → Variables
- Click Add variable
- Key:
SPEKRA_API_KEY - Value: Your Spekra API key
- Check Mask variable (recommended)
- Click Add variable
2. Update Your Pipeline
Add the Spekra environment variable to your test job:
stages:
- test
test:
stage: test
image: mcr.microsoft.com/playwright:v1.40.0-jammy
script:
- npm ci
- npx playwright test
variables:
SPEKRA_API_KEY: $SPEKRA_API_KEY
Full Example
Here's a complete pipeline configuration:
stages:
- test
variables:
npm_config_cache: "$CI_PROJECT_DIR/.npm"
cache:
key: "${CI_COMMIT_REF_SLUG}"
paths:
- .npm/
- node_modules/
test:
stage: test
image: mcr.microsoft.com/playwright:v1.40.0-jammy
script:
- npm ci --cache .npm --prefer-offline
- npx playwright test
variables:
SPEKRA_API_KEY: $SPEKRA_API_KEY
artifacts:
when: always
paths:
- playwright-report/
expire_in: 7 days
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Parallel Testing
For large test suites, use GitLab's parallel feature:
test:
stage: test
image: mcr.microsoft.com/playwright:v1.40.0-jammy
parallel: 4
script:
- npm ci
- npx playwright test --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL
variables:
SPEKRA_API_KEY: $SPEKRA_API_KEY
Spekra automatically aggregates results from all parallel jobs.
Protected Variables
For additional security, mark your API key as protected:
- Go to Settings → CI/CD → Variables
- Edit the
SPEKRA_API_KEYvariable - Check Protect variable
Protected variables are only available to protected branches and tags.
If you protect the variable, make sure your main branch is protected, or the variable won't be available.
Different Environments
Use GitLab environments for different API keys:
test:staging:
stage: test
environment: staging
script:
- npx playwright test
variables:
SPEKRA_API_KEY: $SPEKRA_STAGING_API_KEY
test:production:
stage: test
environment: production
script:
- npx playwright test
variables:
SPEKRA_API_KEY: $SPEKRA_PROD_API_KEY
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Captured Metadata
The reporter automatically captures from GitLab CI:
| Field | Source |
|---|---|
| Job URL | CI_JOB_URL |
| Pipeline | CI_PIPELINE_ID |
| Branch | CI_COMMIT_REF_NAME |
| Commit | CI_COMMIT_SHA |
| Author | CI_COMMIT_AUTHOR |
| Project | CI_PROJECT_NAME |
Merge Request Pipelines
For merge request pipelines, additional metadata is captured:
| Field | Source |
|---|---|
| MR ID | CI_MERGE_REQUEST_IID |
| Source Branch | CI_MERGE_REQUEST_SOURCE_BRANCH_NAME |
| Target Branch | CI_MERGE_REQUEST_TARGET_BRANCH_NAME |
Troubleshooting
Variable Not Available
- Check the variable is not protected (or the branch is protected)
- Verify the variable name matches exactly
- For merge requests from forks, variables may not be available
Results Not Appearing
- Check pipeline logs for errors
- Enable debug: add
SPEKRA_DEBUG: "true"to variables - Verify network access to spekra.dev
Masked Variable Issues
If the masked variable isn't working:
- Ensure the value is at least 8 characters
- The value can only appear in logs as
[MASKED] - If you see the key in logs, it wasn't properly masked
Self-Hosted GitLab
If using self-hosted GitLab, ensure:
- Outbound network access to
spekra.devis allowed - SSL certificates are properly configured
- The runner has network access