diff --git a/resources/schema.json b/resources/schema.json index 37201ea2..2aee89c1 100644 --- a/resources/schema.json +++ b/resources/schema.json @@ -355,6 +355,14 @@ "publishToJUnitReport" : { "type" : "boolean", "description" : "Выполнять публикацию результатов в отчет JUnit.\n По умолчанию включено.\n " + }, + "coverage" : { + "type" : "boolean", + "description" : "Выполнять замер покрытия" + }, + "dbgsPort" : { + "type" : "integer", + "description" : "Порт, на котором будет запущен сервер отладки для замера покрытия" } } }, diff --git a/src/ru/pulsar/jenkins/library/configuration/SmokeTestOptions.groovy b/src/ru/pulsar/jenkins/library/configuration/SmokeTestOptions.groovy index c84df883..562678c3 100644 --- a/src/ru/pulsar/jenkins/library/configuration/SmokeTestOptions.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/SmokeTestOptions.groovy @@ -31,7 +31,7 @@ class SmokeTestOptions implements Serializable { Boolean coverage = false @JsonPropertyDescription("Порт, на котором будет запущен сервер отладки для замера покрытия") - int dbgsPort = 1650 + int dbgsPort = 1550 @Override @NonCPS diff --git a/src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy b/src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy index c285fa1a..c45ae2cc 100644 --- a/src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy @@ -27,6 +27,12 @@ class YaxunitOptions implements Serializable { """) boolean publishToJUnitReport + @JsonPropertyDescription("Выполнять замер покрытия") + Boolean coverage = false + + @JsonPropertyDescription("Порт, на котором будет запущен сервер отладки для замера покрытия") + int dbgsPort = 1550 + @Override @NonCPS String toString() { @@ -35,6 +41,8 @@ class YaxunitOptions implements Serializable { ", configPath='" + configPath + ", publishToAllureReport='" + publishToAllureReport + ", publishToJUnitReport='" + publishToJUnitReport + + ", coverage='" + coverage + + ", dbgsPort='" + dbgsPort + '}' } } diff --git a/src/ru/pulsar/jenkins/library/steps/SonarScanner.groovy b/src/ru/pulsar/jenkins/library/steps/SonarScanner.groovy index 741090ac..5b8c0729 100644 --- a/src/ru/pulsar/jenkins/library/steps/SonarScanner.groovy +++ b/src/ru/pulsar/jenkins/library/steps/SonarScanner.groovy @@ -11,7 +11,7 @@ import ru.pulsar.jenkins.library.utils.VersionParser class SonarScanner implements Serializable { - private final JobConfiguration config; + private final JobConfiguration config SonarScanner(JobConfiguration config) { this.config = config @@ -27,7 +27,7 @@ class SonarScanner implements Serializable { return } - def env = steps.env(); + def env = steps.env() def sonarScannerBinary @@ -63,21 +63,29 @@ class SonarScanner implements Serializable { sonarCommand += " -Dsonar.externalIssuesReportPaths=build/out/edt-generic-issue.json" } - if (config.stageFlags.bdd && config.bddOptions.coverage - || config.stageFlags.smoke && config.smokeTestOptions.coverage) { + def stageFlags = config.stageFlags + + if (stageFlags.bdd && config.bddOptions.coverage + || stageFlags.smoke && config.smokeTestOptions.coverage + || stageFlags.yaxunit && config.yaxunitOptions.coverage) { StringJoiner coveragePathsConstructor = new StringJoiner(",") - if (config.stageFlags.bdd && config.bddOptions.coverage) { + if (stageFlags.bdd && config.bddOptions.coverage) { steps.unstash(Bdd.COVERAGE_STASH_NAME) coveragePathsConstructor.add(Bdd.COVERAGE_STASH_PATH) } - if (config.stageFlags.smoke && config.smokeTestOptions.coverage) { + if (stageFlags.smoke && config.smokeTestOptions.coverage) { steps.unstash(SmokeTest.COVERAGE_STASH_NAME) coveragePathsConstructor.add(SmokeTest.COVERAGE_STASH_PATH) } + if (stageFlags.yaxunit && config.yaxunitOptions.coverage) { + steps.unstash(Yaxunit.COVERAGE_STASH_NAME) + coveragePathsConstructor.add(Yaxunit.COVERAGE_STASH_PATH) + } + String coveragePaths = coveragePathsConstructor.toString() sonarCommand += " -Dsonar.coverageReportPaths=${coveragePaths}" diff --git a/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy b/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy index 2587d0bb..2220c67b 100644 --- a/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy +++ b/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy @@ -1,6 +1,7 @@ package ru.pulsar.jenkins.library.steps import hudson.FilePath +import org.apache.commons.lang.RandomStringUtils import ru.pulsar.jenkins.library.IStepExecutor import ru.pulsar.jenkins.library.configuration.JobConfiguration @@ -16,6 +17,8 @@ class Yaxunit implements Serializable { private final String DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE = 'yaxunit.json' public static final String YAXUNIT_ALLURE_STASH = 'yaxunit-allure' + public static final String COVERAGE_STASH_NAME = 'yaxunit-coverage' + public static final String COVERAGE_STASH_PATH = 'build/out/yaxunit-coverage.xml' Yaxunit(JobConfiguration config) { this.config = config @@ -62,9 +65,28 @@ class Yaxunit implements Serializable { } - // Выполяем команды - steps.withEnv(logosConfig) { - VRunner.exec(runTestsCommand, true) + def coverageOpts = config.coverageOptions + def port = options.dbgsPort + def lockableResource = RandomStringUtils.random(9, true, false) + if (options.coverage) { + lockableResource = "${env.NODE_NAME}_$port" + } + + steps.lock(null, 1, lockableResource) { + if (options.coverage) { + steps.start("${coverageOpts.dbgsPath} --addr=127.0.0.1 --port=$port") + steps.start("${coverageOpts.coverage41CPath} start -i DefAlias -u http://127.0.0.1:$port -P $workspaceDir -s $srcDir -o $COVERAGE_STASH_PATH") + steps.cmd("${coverageOpts.coverage41CPath} check -i DefAlias -u http://127.0.0.1:$port") + } + + // Выполняем команды + steps.withEnv(logosConfig) { + VRunner.exec(runTestsCommand, true) + } + + if (options.coverage) { + steps.cmd("${coverageOpts.coverage41CPath} stop -i DefAlias -u http://127.0.0.1:$port") + } } // Сохраняем результаты @@ -86,5 +108,9 @@ class Yaxunit implements Serializable { steps.stash(YAXUNIT_ALLURE_STASH, "$allureReportDir/**", true) } + + if (options.coverage) { + steps.stash(COVERAGE_STASH_NAME, COVERAGE_STASH_PATH, true) + } } }