1

I'm trying to develop a SonarQube (Compute Engine) plugin and I need to use the credentials (sonar.user // sonar.password) in order to invoke web services from within the plugin itself.

I try declaring the use of them in the Plugin class, e.g.:

@Override
public void define(Plugin.Context context) {

    ...

    context.addExtensions(asList(
            PropertyDefinition.builder(SONAR_USER)
                    .name("Sonar user")
                    .description("SonarQube user")
                    .onQualifiers(Qualifiers.PROJECT)
                    .type(PropertyType.STRING)
                    .defaultValue("admin")
                    .build()
 ...

Then in the hook:

 public class Hook implements PostProjectAnalysisTask {

    private final Server server;
    private final Settings settings;

    public Hook(Server server, Settings settings) {
        this.server = server;
        this.settings = settings;
    }

    @Override
    public void finished(ProjectAnalysis projectAnalysis) {
        final HttpConnector httpConnector =
                HttpConnector.newBuilder()
                  .url(server.getURL())
                  .credentials(                                    
                    settings.getString(CePlugin.SONAR_USER), // null
                    settings.getString(CePlugin.SONAR_PASSWORD) // null
                   ).build();
        final WsClient wsClient = WsClientFactories.getDefault().newClient(httpConnector);
    }
 }

But when I inject Settings inside the hook the property is not available.

How do I retrieve sonar.user and sonar.password so that I can invoke the Web Service API?

Alix
  • 2,630
  • 30
  • 72
  • Calling web services from Compute Engine is not recommended. Which kind of information are missing from ProjectAnalysis ? Can you describe your need please ? – Simon Brandhof Apr 11 '17 at 19:01
  • Hi, the plugin is about automatically relocating a project to another quality gate after an analysis. So possibilities to fetch QG ids based on names and to select a QG for a project. I'm using QGs as quality level and if a project passes it is promoted to a stricter QG – Alix Apr 11 '17 at 19:14

0 Answers0