diff --git a/vars/sonar-scanner.groovy b/vars/sonar-scanner.groovy new file mode 100644 index 0000000..d63db18 --- /dev/null +++ b/vars/sonar-scanner.groovy @@ -0,0 +1,26 @@ +import com.cloudbees.groovy.cps.NonCPS +import groovy.transform.Field + +@Field def sonarCommand + +def call(String rootFile = 'src/cf/Configuration.xml') { + + String scannerHome = tool 'sonar-scanner' + sonarCommand = "$scannerHome/bin/sonar-scanner -Dsonar.branch.name=$env.BRANCH_NAME" + + def configurationText = readFile encoding: 'UTF-8', file: rootFile + String configurationVersion = version(configurationText) + if (configurationVersion) { + sonarCommand += " -Dsonar.projectVersion=$configurationVersion" + } + + withSonarQubeEnv('qa.dev.pulsar.ru') { + cmd sonarCommand + } +} + +@NonCPS +private static String version(String text) { + def matcher = text =~ /(.*)<\/Version>/ + return matcher ? matcher.group(1) : "" +} \ No newline at end of file