SonarSource/sonarqube · warning
Cannot mint a GitLab access token: project '{}' is not bound
Error message
Cannot mint a GitLab access token: project '{}' is not bound to any DevOps Platform What it means
mint() found the project, but projectAlmSettingDao().selectByProject() returned nothing, meaning the project has no ALM/DevOps platform binding. GitLab token minting requires a bound GitLab project, so the method logs this warning and returns Optional.empty().
Source
Thrown at server/sonar-webserver-common/src/main/java/org/sonar/server/common/almsettings/gitlab/GitlabScmAccessTokenProvider.java:103
this.dbClient = dbClient;
this.gitlabGlobalSettingsValidator = gitlabGlobalSettingsValidator;
this.gitlabApplicationClient = gitlabApplicationClient;
this.encryption = settings.getEncryption();
}
@Override
public Optional<ScmAccessToken> mint(String projectKey) {
String safeProjectKey = sanitizeForLog(projectKey);
TokenMintRequest request;
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<ProjectDto> project = dbClient.projectDao().selectProjectByKey(dbSession, projectKey);
if (project.isEmpty()) {
LOG.warn("Cannot mint a GitLab access token: unknown project '{}'", safeProjectKey);
return Optional.empty();
}
Optional<ProjectAlmSettingDto> projectAlmSetting = dbClient.projectAlmSettingDao().selectByProject(dbSession, project.get());
if (projectAlmSetting.isEmpty()) {
LOG.warn("Cannot mint a GitLab access token: project '{}' is not bound to any DevOps Platform", safeProjectKey);
return Optional.empty();
}
Optional<AlmSettingDto> almSetting = dbClient.almSettingDao().selectByUuid(dbSession, projectAlmSetting.get().getAlmSettingUuid());
if (almSetting.isEmpty() || almSetting.get().getAlm() != ALM.GITLAB) {
return Optional.empty();
}
Long gitlabProjectId = parseGitlabProjectId(projectAlmSetting.get().getAlmRepo(), safeProjectKey);
if (gitlabProjectId == null) {
return Optional.empty();
}
request = new TokenMintRequest(new TokenCacheKey(requireNonNull(project.get().getUuid(), "Project UUID cannot be null"),
requireNonNull(almSetting.get().getUuid(), "ALM setting UUID cannot be null"), gitlabProjectId, almSetting.get().getUpdatedAt()), safeProjectKey,
almSetting.get());
}
// GitLab API calls below are network I/O, deliberately made outside the DbSession above, so a
// pooled DB connection is not held for their duration.
return Optional.of(getOrCreateToken(request));View on GitHub (pinned to 184c821202)
Solutions
- Bind the project to a GitLab DevOps platform setting (Project Settings > DevOps Platform Integration, or api/alm_settings/set_gitlab).
- Ensure the ALM setting itself exists and is of type GITLAB before binding.
- Re-run project import (api/alm_settings/import_bindings) if the binding was lost during migration.
- Handle the empty Optional as 'not integrated' rather than retrying mint.
Example fix
// before
provider.mint("my.project"); // project not bound -> empty
// after
almSettingsService.setGitlabProjectSetting(db, "my.project", almSettingUuid, "12345");
Optional<ScmAccessToken> token = provider.mint("my.project"); Defensive patterns
Strategy: validation
Validate before calling
// before minting, verify the ALM binding exists
Optional<ProjectAlmSettingDto> binding =
dbClient.projectAlmSettingDao().selectByProject(dbSession, projectDto);
if (binding.isEmpty()) { throw new IllegalStateException("Project not bound to a DevOps platform"); } Type guard
boolean isBoundToAlm(DbSession db, ProjectDto project) {
return dbClient.projectAlmSettingDao().selectByProject(db, project).isPresent();
} Prevention
- Bind every provisioned project to a GitLab ALM setting as part of provisioning.
- Run api/alm_settings/import_bindings after bulk imports.
- Audit unbound projects periodically (api/projects + binding status).
- Fail provisioning early when binding step is skipped.
When it happens
Trigger: Calling mint(projectKey) for a project that exists in SonarQube but was never bound to a DevOps platform setting (PROJECT_BINDINGS not configured), or whose binding was deleted.
Common situations: Manually created projects without DevOps platform integration; import/bind step skipped in provisioning; admin removed the ALM binding; project imported via another mechanism (e.g. generic import) losing the binding.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Cannot mint a GitLab access token: unknown project '{}'
- Cannot mint a GitLab access token: project '{}' has no repos
- GitLab repository id is not numeric: '%s'
- Cannot mint a GitLab access token: project '{}' has a non-nu
- Failed to authenticate with login '%s'
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/52b6280950acac1a.
Report an issue: GitHub.