SonarSource/sonarqube · warning
Failed to count repos for ALM setting
Error message
Failed to count {} repos for ALM setting '{}' What it means
PatAlmRepoCountProvider (used for Azure DevOps/GitLab) decrypts the stored PAT and counts repos via the provider API. Failures while counting repos for the ALM setting are logged with the provider type and setting key, returning OptionalLong.empty().
Solutions
- Re-enter/update the PAT for the ALM setting — expired tokens are the most common cause
- Check the attached exception for HTTP/auth errors from the provider
- Verify network access and TLS trust from SonarQube to the provider URL
- Ensure the token's account has permission to enumerate the repos/projects
Defensive patterns
Strategy: fallback
Validate before calling
String pat = decryptor.decrypt(secret); if (pat == null || pat.isBlank()) return OptionalLong.empty();
Try / catch
try { return countRepos(primary, pat); } catch (Exception e) { LOG.warn("Failed to count {} repos for ALM setting '{}'", supportedAlm(), key, e); return OptionalLong.empty(); } Prevention
- Keep PATs valid and scoped to repo enumeration
- Verify provider URL reachability and TLS trust
- Grant the token's account permission to list repos
When it happens
Trigger: In fetchTotalCount: the secret decryptor returns null (count silently skipped) or any Exception occurs during countRepos — bad PAT, unreachable Azure DevOps/GitLab host, API error.
Common situations: Rotated or revoked personal access tokens; self-hosted GitLab/Azure URLs unreachable; TLS certificate issues; user lacking permission to list projects/repos.
Related errors
- Failed to authenticate with login
- Global personal access tokens ("All accessible…
- Invalid Azure URL or Personal Access Token
- Invalid personal access token
- allowAllGroups can only be enabled when Auto-provisioning…
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/3ec923df5b208971.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/onboarding/alm/OnboardingAlmConfiguration.java:192
}
protected abstract OptionalLong countRepos(String primary, String pat);
@Override
public OptionalLong fetchTotalCount(OnboardingRows.AlmSetting setting, OnboardingSecretDecryptor decryptor) {
String primary = primaryField(setting);
String secret = secretField(setting);
if (primary == null || secret == null) {
return OptionalLong.empty();
}
try {
String pat = decryptor.decrypt(secret);
if (pat == null) {
return OptionalLong.empty();
}
return countRepos(primary, pat);
} catch (Exception e) {
LOG.warn("Failed to count {} repos for ALM setting '{}'", supportedAlm(), setting.key(), e);
return OptionalLong.empty();
}
}
}
private static final class GitlabAlmRepoCountProvider extends PatAlmRepoCountProvider {
private final GitlabApplicationClient client;
private GitlabAlmRepoCountProvider(GitlabApplicationClient client) {
this.client = client;
}
@Override
public String supportedAlm() {
return "gitlab";
}
View on GitHub (pinned to 184c821202)