Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import hudson.model.*
import hudson.maven.*
import hudson.tasks.*
import hudson.plugins.sonar.*

def newSonarInstance="Sonar Prod";

def listOfSonarInstance=SonarInstallation.all()*.name;

assertif (!listOfSonarInstance.contains(newSonarInstance)) {
  println('Please define newSonarInstance value to an existing Sonar installation. Possible values are: ' + listOfSonarInstance);
  return;
}

// For each project
for(item in Hudson.instance.items) {
  if(item instanceof FreeStyleProject) {
    for (builder in item.buildersList){
      if (builder instanceof SonarRunnerBuilder && !listOfSonarInstance.contains(builder.installationName)) {
        def newBuilder = new SonarRunnerBuilder(newSonarInstance,builder.sonarRunnerName,builder.project,builder.@properties,builder.javaOpts);
        item.buildersList.replace(newBuilder);
        println("JOB: " + item.name + " fixed");
      }
    }
  }
  if(item instanceof FreeStyleProject || item instanceof AbstractMavenProject) {
    for (publisher in item.publishersList){
      if (publisher instanceof SonarPublisher && !listOfSonarInstance.contains(publisher.installationName)) {
        def newPublisher = new SonarPublisher(newSonarInstance,publisher.branch,publisher.language,publisher.triggers,publisher.jobAdditionalProperties,publisher.mavenOpts,publisher.mavenInstallationName,publisher.rootPom);
        item.publishersList.replace(newPublisher);
        println("JOB: " + item.name + " fixed");
      }
    }
  }
}