You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将SonarQube扫描报告发布至多个SonarQube实例?

Hey Sandeep, nice question! Getting your scan results sent to two separate SonarQube instances (6.1 Dev Edition and 6.7 LTS) is totally feasible—let’s break down how to do it based on your build tool setup:

Method 1: SonarScanner CLI (Universal Approach)

This works for any project type, regardless of build tool. You’ll just run the scanner twice, once for each instance:

  • First, make sure you have the SonarScanner CLI installed that’s compatible with both 6.1 and 6.7 (stick to versions around 4.7.x or older to avoid compatibility issues).
  • Run two separate scan commands, each pointing to a different instance. You can either pass all parameters directly in the command, or use separate property files for cleaner setup:
    • Direct command example for 6.1 Dev Edition:
      sonar-scanner -Dsonar.host.url=http://your-sonar-61:9000 -Dsonar.login=your-61-auth-token -Dsonar.projectKey=your-project-key -Dsonar.projectName=YourProject
    • Direct command example for 6.7 LTS:
      sonar-scanner -Dsonar.host.url=http://your-sonar-67:9000 -Dsonar.login=your-67-auth-token -Dsonar.projectKey=your-project-key -Dsonar.projectName=YourProject
  • Pro tip: Create two property files (e.g., sonar-61.properties and sonar-67.properties) with all the configs for each instance, then run:
    sonar-scanner -Dsonar.properties=sonar-61.properties
    sonar-scanner -Dsonar.properties=sonar-67.properties
Method 2: Maven Projects

If you’re using Maven, you can configure the SonarQube plugin to run two separate executions in your pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>org.sonarsource.scanner.maven</groupId>
      <artifactId>sonar-maven-plugin</artifactId>
      <version>3.9.1.2184</version> <!-- Compatible with both 6.1 and 6.7 -->
      <executions>
        <!-- Publish to 6.1 Dev Edition -->
        <execution>
          <id>sonar-dev-61</id>
          <phase>verify</phase>
          <goals>
            <goal>sonar</goal>
          </goals>
          <configuration>
            <sonar.host.url>http://your-sonar-61:9000</sonar.host.url>
            <sonar.login>your-61-auth-token</sonar.login>
            <sonar.projectKey>your-project-key</sonar.projectKey>
          </configuration>
        </execution>
        <!-- Publish to 6.7 LTS -->
        <execution>
          <id>sonar-lts-67</id>
          <phase>verify</phase>
          <goals>
            <goal>sonar</goal>
          </goals>
          <configuration>
            <sonar.host.url>http://your-sonar-67:9000</sonar.host.url>
            <sonar.login>your-67-auth-token</sonar.login>
            <sonar.projectKey>your-project-key</sonar.projectKey>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
  • Just run mvn verify and the plugin will automatically execute both scans and push results to each instance.
Method 3: Gradle Projects

For Gradle, you can define two distinct SonarQube tasks, each targeting one instance:

plugins {
  id 'org.sonarqube' version '3.3' // Compatible with 6.1 and 6.7
}

// Task for 6.1 Dev Edition
task sonar61(type: SonarQubeTask) {
  properties {
    property 'sonar.host.url', 'http://your-sonar-61:9000'
    property 'sonar.login', 'your-61-auth-token'
    property 'sonar.projectKey', 'your-project-key'
    property 'sonar.projectName', 'YourProject'
  }
}

// Task for 6.7 LTS
task sonar67(type: SonarQubeTask) {
  properties {
    property 'sonar.host.url', 'http://your-sonar-67:9000'
    property 'sonar.login', 'your-67-auth-token'
    property 'sonar.projectKey', 'your-project-key'
    property 'sonar.projectName', 'YourProject'
  }
}

// Optional: Bind both tasks to the build lifecycle
build.dependsOn sonar61, sonar67
  • Run ./gradlew sonar61 sonar67 to execute both scans, or just ./gradlew build if you’ve bound them to the build task.
Key Notes to Keep in Mind
  • Compatibility: Always use a scanner/plugin version that works with both SonarQube instances. Older versions (like the ones suggested above) are safer here since newer scanners may drop support for pre-7.x SonarQube versions.
  • Auth Tokens: Generate separate tokens for each instance (go to My Account > Security in each SonarQube UI) to avoid sharing credentials across environments.
  • CI/CD Integration: If you’re using a CI tool like Jenkins or GitLab CI, just add two separate scan steps (one for each instance) to your pipeline. You can run them in parallel if your resources allow, to save time.

内容的提问来源于stack exchange,提问作者Sandeep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:37:56