GitLab CI
For now, only the following OS and versions are supported on the runners:
- Ubuntu 20.04 and later
- Debian 11 and later
Setup
1. Allow the Gitlab CI workflow to upload on CodSpeed
You need to get your CodSpeed Token. There are multiple ways to retrieve it:
- Once you enable a repository on CodSpeed, you'll be prompted to copy the token
- You can also find it on the repository settings page
Be mindful that a token is scoped to a specific repository. Make sure that you are on the correct repository settings page when copying the token.
Then, create a new
CI/CD variable in your
repository with the name CODSPEED_TOKEN
and the value of your token.
Set the CODSPEED_TOKEN
variable as "Masked"
, but not "Protected"
, because
it must be available on all branches.
2. Create the benchmarks job
The next step is to 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:
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_BRANCH
codspeed:
stage: test
image: <your-docker-image> # for example: python:3.12 or rust:1.82
variables:
# refer to https://github.com/CodSpeedHQ/runner/releases for available versions
CODSPEED_RUNNER_VERSION: 3.2.1
before_script:
# ...
# Setup your environment here:
# - Configure your Python/Rust/Node version
# - Install your dependencies
# - Build your benchmarks (if using a compiled language)
# ...
- curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$CODSPEED_RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet
- source $HOME/.cargo/env
script:
- codspeed run -- "<Insert your benchmark command here>"
Sample configurations
- Python
- Rust
- Node.js
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_BRANCH
codspeed:
stage: test
image: python:3.12
variables:
CODSPEED_RUNNER_VERSION: 3.2.1
before_script:
- pip install -r requirements.txt
- curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$CODSPEED_RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet
- source $HOME/.cargo/env
script:
- codspeed run -- pytest tests/ --codspeed
More info on how to setup Python benchmarks.
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_BRANCH
codspeed:
stage: test
image: rust:1.82
variables:
CODSPEED_RUNNER_VERSION: 3.2.1
before_script:
- curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$CODSPEED_RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet
# Build the benchmark target(s)
- cargo codspeed build
script:
# Run the benchmarks
- cargo codspeed run
More info on how to setup Rust benchmarks.
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_BRANCH
codspeed:
stage: test
image: nodejs:22
variables:
CODSPEED_RUNNER_VERSION: 3.2.1
before_script:
- npm install
- curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$CODSPEED_RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet
- source $HOME/.cargo/env
script:
- codspeed run -- node -r esbuild-register benches/bench.ts
More info on how to setup Node.js benchmarks.
CodSpeed only currently supports docker images that are based on Ubuntu or Debian.
3. Check the results
Once the workflow is created, your merge requests will receive a performance report comment and will also receive some additional checks:
4. Next Steps
Now that everything is up and running (and hopefully green 🎉), you can start enhancing your workflow to get the most out of CodSpeed.