Skip to content

GitLab Integration Guide

This guide will help you set up GitLab CI to report your test results to Deflaker.

Prerequisites

  • A Deflaker account with an API key
  • A GitLab repository with tests that generate JUnit XML reports

Configuration Steps

1. Add Your API Key

In your GitLab repository, add your Deflaker API key as a CI/CD variable:

  1. Go to Settings > CI/CD > Variables
  2. Click Add Variable
  3. Set the key as DEFLAKER_API_KEY
  4. Paste your API key as the value
  5. Make sure to mark it as Masked but not Protected

2. Update .gitlab-ci.yml

Add the following to your .gitlab-ci.yml file:

# Example configuration for a Java project using Maven
test:
  script:
    - mvn test
  artifacts:
    reports:
      junit: target/surefire-reports/TEST-*.xml
    expire_in: 1 week
  after_script:
    - |
      if [ -d "target/surefire-reports" ]; then
        for report in target/surefire-reports/TEST-*.xml; do
          curl -X POST "https://api.deflaker.com/api/v1/test-results" \
            -H "X-API-Key: $DEFLAKER_API_KEY" \
            -H "X-Project-Name: $CI_PROJECT_NAME" \
            -H "X-Pipeline-ID: $CI_PIPELINE_ID" \
            -H "X-Branch: $CI_COMMIT_REF_NAME" \
            -F "report=@$report"
        done
      fi