Learn how to setup CodSpeed and run benchmarks within your GitLab CI workflow
Running benchmarks in CI environments presents unique challenges due to the
inherent noise and variability of shared cloud infrastructure. Standard hosted
runners can exhibit significant performance variance.
CodSpeed instruments are designed to mitigate these challenges
and gather accurate performance data even in noisy environments. The easiest way
to get started running benchmarks in GitLab CI is to use the
CodSpeed Runner directly.
For now, only the following OS and versions are supported on the runners:
Create a new job to run the benchmarks for your repository.For example, you can add this job to your existing pipeline by adding a section
in your .gitlab-ci.yml file with the following content:
.gitlab-ci.yml
Copy
Ask AI
workflow: # run on merge requests and pushes on the default branch rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCHcodspeed: stage: test image: <your-docker-image> # for example: python:3.12 or rust:1.82 id_tokens: # OpenID Connect token to authenticate with CodSpeed CODSPEED_TOKEN: aud: codspeed.io before_script: # ... # Setup your environment here: # - Configure your Python/Rust/Node version # - Install your dependencies # - Build your benchmarks (if using a compiled language) # ... # Use the latest CodSpeed version - curl -fsSL https://github.com/CodSpeedHQ/runner/releases/latest/download/codspeed-runner-installer.sh | bash -s -- --quiet # Or set a specific version. Refer to https://github.com/CodSpeedHQ/runner/releases for available versions. For example: # - curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v4.2.1/codspeed-runner-installer.sh | bash -s -- --quiet script: - codspeed run --mode instrumentation -- "<Insert your benchmark command here>"
Make sure to run the job on merge_request_event. This is required to have
reports on merge requests correctly working.Learn more about
baseline report selection.