SonarSource/sonarqube · error · IllegalStateException

It is not possible to synchronize SonarQube using GitLab…

Error message

It is not possible to synchronize SonarQube using GitLab, as it is already managed by .

What it means

SonarQube allows only one identity provider to manage instance-level provisioning at a time. checkInstanceNotManagedByAnotherProvider throws this IllegalStateException from the GitLab config flow when ManagedInstanceService reports the instance is already externally managed by a provider other than 'gitlab'.

Solutions

  1. Disable/unmanage the current identity provider integration (e.g. GitHub or Azure DevOps provisioning) before configuring GitLab synchronization.
  2. Verify which provider manages the instance via the managed instance settings/API.
  3. If the other integration was already removed, ensure the managed-instance flag was cleared in the database.

Example fix

// before
POST /api/gitlab/configure (instance managed by GitHub)

// after
DELETE /api/github/configuration (unmanage instance first)
POST /api/gitlab/configure
Defensive patterns

Strategy: try-catch

Validate before calling

// check before configuring GitLab sync
if (managedInstanceService.isInstanceExternallyManaged() && !"gitlab".equals(managedInstanceService.getProviderName())) {
  throw new IllegalStateException("Instance managed by another provider");
}

Try / catch

try { service.createConfiguration(params); } catch (IllegalStateException e) { log.error("Resolve existing provider first: {}", e.getMessage()); }

Prevention

When it happens

Trigger: Creating or updating a GitLab configuration (via throwIfConfigIncompleteOrInstanceAlreadyManaged) while the instance is managed by a different provider, e.g. GitHub or Azure DevOps; note that providerName=="gitlab" is allowed through.

Common situations: Migrating between identity providers without first unmanaging the instance; enabling GitHub integration and GitLab sync simultaneously; stale managed-instance state after removing a previous integration.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at server/sonar-webserver-common/src/main/java/org/sonar/server/common/gitlab/config/GitlabConfigurationService.java:320

  }

  private void triggerRun(GitlabConfiguration gitlabConfiguration) {
    throwIfConfigIncompleteOrInstanceAlreadyManaged(gitlabConfiguration);
    managedInstanceService.queueSynchronisationTask(userSession.getUuid());
  }

  private void throwIfConfigIncompleteOrInstanceAlreadyManaged(GitlabConfiguration configuration) {
    checkInstanceNotManagedByAnotherProvider();
    checkState(AUTO_PROVISIONING.equals(configuration.provisioningType()), "Auto provisioning must be activated");
    checkState(configuration.enabled(), getErrorMessage("GitLab authentication must be turned on"));
    checkState(isNotBlank(configuration.provisioningToken()), getErrorMessage("Provisioning token must be set"));
  }

  private void checkInstanceNotManagedByAnotherProvider() {
    if (managedInstanceService.isInstanceExternallyManaged()) {
      Optional.of(managedInstanceService.getProviderName()).filter(providerName -> !"gitlab".equals(providerName))
        .ifPresent(providerName -> {
          throw new IllegalStateException("It is not possible to synchronize SonarQube using GitLab, as it is already managed by "
            + providerName + ".");
        });
    }
  }

  private static String getErrorMessage(String prefix) {
    return format("%s to enable GitLab provisioning.", prefix);
  }

  public Optional<String> validate(GitlabConfiguration gitlabConfiguration) {
    if (!gitlabConfiguration.enabled()) {
      return Optional.empty();
    }
    String url = (gitlabConfiguration.url() + "/api/v4").replace("//", "/");
    try {
      gitlabGlobalSettingsValidator.validate(
        toValidationMode(gitlabConfiguration.provisioningType()),
        url,

View on GitHub (pinned to 184c821202)