SonarSource/sonarqube · warning

Cannot mint a GitLab access token: unknown project '{}'

Error message

Cannot mint a GitLab access token: unknown project '{}'

What it means

GitlabScmAccessTokenProvider.mint() looks up the project by its SonarQube key before requesting a GitLab personal access token. If no ProjectDto exists for the given key in the database, it logs this warning and returns Optional.empty() instead of a token. It is a lookup failure, not a crash: the caller receives an empty Optional.

Source

Thrown at server/sonar-webserver-common/src/main/java/org/sonar/server/common/almsettings/gitlab/GitlabScmAccessTokenProvider.java:98

    .build();
  private final Striped<Lock> tokenRefreshLocks = Striped.lazyWeakLock(128);

  public GitlabScmAccessTokenProvider(DbClient dbClient, GitlabGlobalSettingsValidator gitlabGlobalSettingsValidator,
    GitlabApplicationClient gitlabApplicationClient, Settings settings) {
    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());

View on GitHub (pinned to 184c821202)

Solutions

  1. Verify the project key exists (Projects administration page or GET api/projects/show?key=...) and use the exact key in the mint call.
  2. If the project was deleted, recreate/import it and rebind the DevOps platform before minting.
  3. If the key was renamed, update the caller (CI job, script, provisioning config) with the new key.
  4. Handle Optional.empty() from mint() gracefully and surface a clear message instead of retrying.

Example fix

// before
Optional<ScmAccessToken> token = provider.mint("com.example.app_old");
// after
Optional<ProjectDto> project = dbClient.projectDao().selectProjectByKey(db, actualKey);
if (project.isPresent()) {
  Optional<ScmAccessToken> token = provider.mint(actualKey);
}
Defensive patterns

Strategy: validation

Validate before calling

// Java
dbClient.projectDao().selectProjectByKey(dbSession, projectKey)
  .orElseThrow(() -> new IllegalStateException("Unknown SonarQube project key: " + projectKey));
// then call mint(projectKey)

Type guard

boolean isKnownProject(DbSession db, String key) {
  return dbClient.projectDao().selectProjectByKey(db, key).isPresent();
}

Prevention

When it happens

Trigger: Calling mint(projectKey) with a project key that does not exist in SonarQube (deleted project, typo in key, wrong branch/monorepo key casing).

Common situations: CI pipelines configured with a stale project key after the project was deleted or its key was renamed; provisioning scripts that mint tokens before the project import finishes; typos in ALM-bound project keys.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/92b619e8ffb0290c. Report an issue: GitHub.