Enterprise · Code references
Set up with GitLab CI
One reviewed job and three CI/CD variables make every push to the default branch update the flag's code references.
Video coming soon
Set up with GitLab CI
Before you start
- A system client token with the scopes Code references write and Evaluate (Overview).
- The Maintainer role on the GitLab project, to add CI/CD variables.
Add the job
-
Add the job to
.gitlab-ci.yml. The job receivesFLUXGATE_TOKEN, so run only a copy you reviewed:-
Copy the job (recommended). Download
fluxgate-code-refs.gitlab-ci.yml, review it and paste it into.gitlab-ci.yml. The job then changes only when you change it. -
Include it with a checksum. With
integrity(GitLab 17.9 or later), GitLab runs the remote file only when its SHA-256 matches. Download and review the file, then print the value from that copy:bashopenssl dgst -sha256 -binary fluxgate-code-refs.gitlab-ci.yml | openssl base64 -Ayamlinclude: - remote: https://flux.forgeopslabs.com/downloads/code-refs/fluxgate-code-refs.gitlab-ci.yml integrity: sha256-<the value printed above>When the template changes, the pipeline fails until you review the new file and update
integrity. Do not include the file withoutintegrity: a changed file would run with your token.
-
-
In GitLab, open Settings, CI/CD, Variables. Add
FLUXGATE_URL(your API URL, such ashttps://flags.example.com/api/v1),FLUXGATE_TOKEN(the system client token, masked) andFLUXGATE_VERSION(the FluxGate release, such asv2.0.1; the job downloads its CLI fromhttps://flux.forgeopslabs.com/downloads/releases/<version>/). -
Push to the default branch. The job
fluxgate-code-refsruns.
The job runs on debian:bookworm-slim, because the CLI build needs glibc. It runs only on the default branch ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH), downloads the CLI archive, checks it against SHA256SUMS, and scans. The scanner reads the project path, branch, commit and default branch from GitLab's CI variables.
Deleted branches and more branches
GitLab runs no pipeline when a branch is deleted. A daily job on the backend deletes branch scans that got no upload for 30 days. To delete one at once, run this with a token that has Code references write:
fluxgate code-refs prune --repo gitlab.com/acme/shop --branch old-branchThe job scans the default branch only. To scan a release branch too, extend its rules:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "release"Removal issues
A pipeline schedule can run the job fluxgate-cleanup-issues, which opens one issue per flag whose code should be removed. See Open removal issues.
Optional variables
| Variable | Meaning |
|---|---|
FLUXGATE_DOWNLOAD_BASE | Download the CLI and SHA256SUMS from here instead of https://flux.forgeopslabs.com/downloads/releases/<version>, for example a mirror inside your network |
FLUXGATE_CONTEXT_LINES | Lines sent above and below each match, 0 to 5. Default 1. Use 0 to send no code |
FLUXGATE_SCAN_ARGS | Extra scan arguments, separated by spaces and written without quotes, for example --exclude generated/** |
For a self-managed GitLab, the scanner builds the repository name from CI_SERVER_HOST and CI_PROJECT_PATH. Lines on the feature page link to files only for github.com and gitlab.com; for other hosts add --browse-url to FLUXGATE_SCAN_ARGS, for example --browse-url https://git.example.com/acme/shop/src/{commit}/{path}. The template must contain {path} and may contain {commit}, {branch} and {line}.