diff --git a/resources/globalConfiguration.json b/resources/globalConfiguration.json index 8f79812..d5a8f69 100644 --- a/resources/globalConfiguration.json +++ b/resources/globalConfiguration.json @@ -50,6 +50,11 @@ ], "vrunnerSettings": "./tools/vrunner.json" }, + "smoke": { + "vrunnerSettings": "./tools/vrunner.json", + "publishToAllureReport": false, + "publishToJUnitReport": true + }, "resultsTransform": { "removeSupport": true, "supportLevel": 0 diff --git a/resources/schema.json b/resources/schema.json index 0532694..d45308b 100644 --- a/resources/schema.json +++ b/resources/schema.json @@ -151,6 +151,25 @@ } } }, + "smoke" : { + "type" : "object", + "id" : "urn:jsonschema:ru:pulsar:jenkins:library:configuration:SmokeTestOptions", + "description" : "Настройки дымового тестирования", + "properties" : { + "vrunnerSettings" : { + "type" : "string", + "description" : "Путь к конфигурационному файлу vanessa-runner.\n По умолчанию содержит значение \"./tools/vrunner.json\".\n " + }, + "publishToAllureReport" : { + "type" : "boolean", + "description" : "Выполнять публикацию результатов в отчет Allure.\n По умолчанию выключено.\n " + }, + "publishToJUnitReport" : { + "type" : "boolean", + "description" : "Выполнять публикацию результатов в отчет JUnit.\n По умолчанию включено.\n " + } + } + }, "resultsTransform" : { "type" : "object", "id" : "urn:jsonschema:ru:pulsar:jenkins:library:configuration:ResultsTransformOptions", diff --git a/src/ru/pulsar/jenkins/library/IStepExecutor.groovy b/src/ru/pulsar/jenkins/library/IStepExecutor.groovy index 243763b..a41cbeb 100644 --- a/src/ru/pulsar/jenkins/library/IStepExecutor.groovy +++ b/src/ru/pulsar/jenkins/library/IStepExecutor.groovy @@ -17,6 +17,8 @@ interface IStepExecutor { FileWrapper[] findFiles(String glob, String excludes) + String readFile(String file) + String readFile(String file, String encoding) boolean fileExists(String file) @@ -73,5 +75,7 @@ interface IStepExecutor { def allure(List results) + def junit(String testResults, boolean allowEmptyResults) + def installLocalDependencies() } \ No newline at end of file diff --git a/src/ru/pulsar/jenkins/library/StepExecutor.groovy b/src/ru/pulsar/jenkins/library/StepExecutor.groovy index c5b6368..8d1ab2a 100644 --- a/src/ru/pulsar/jenkins/library/StepExecutor.groovy +++ b/src/ru/pulsar/jenkins/library/StepExecutor.groovy @@ -33,7 +33,7 @@ class StepExecutor implements IStepExecutor { } @Override - String readFile(String file, String encoding) { + String readFile(String file, String encoding = 'UTF-8') { steps.readFile encoding: encoding, file: file } @@ -174,6 +174,11 @@ class StepExecutor implements IStepExecutor { ]) } + @Override + def junit(String testResults, boolean allowEmptyResults) { + steps.junit testResults: testResults, allowEmptyResults: allowEmptyResults + } + @Override def installLocalDependencies() { steps.installLocalDependencies() diff --git a/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy b/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy index 4689a6f..34c06c2 100644 --- a/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy @@ -1,7 +1,6 @@ package ru.pulsar.jenkins.library.configuration import com.cloudbees.groovy.cps.NonCPS -import com.fasterxml.jackson.annotation.JsonEnumDefaultValue import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonPropertyDescription @@ -45,6 +44,10 @@ class JobConfiguration implements Serializable { @JsonPropertyDescription("Настройки синтаксического контроля") SyntaxCheckOptions syntaxCheckOptions; + @JsonProperty("smoke") + @JsonPropertyDescription("Настройки дымового тестирования") + SmokeTestOptions smokeTestOptions; + @JsonProperty("resultsTransform") @JsonPropertyDescription("Настройки трансформации результатов анализа") ResultsTransformOptions resultsTransformOptions; @@ -67,6 +70,7 @@ class JobConfiguration implements Serializable { ", bddOptions=" + bddOptions + ", sonarQubeOptions=" + sonarQubeOptions + ", syntaxCheckOptions=" + syntaxCheckOptions + + ", smokeTestOptions=" + smokeTestOptions + ", resultsTransformOptions=" + resultsTransformOptions + ", logosConfig=" + logosConfig + '}'; diff --git a/src/ru/pulsar/jenkins/library/configuration/SmokeTestOptions.groovy b/src/ru/pulsar/jenkins/library/configuration/SmokeTestOptions.groovy new file mode 100644 index 0000000..f58efb0 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/configuration/SmokeTestOptions.groovy @@ -0,0 +1,34 @@ +package ru.pulsar.jenkins.library.configuration + +import com.cloudbees.groovy.cps.NonCPS +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonPropertyDescription + +@JsonIgnoreProperties(ignoreUnknown = true) +class SmokeTestOptions implements Serializable { + + @JsonPropertyDescription("""Путь к конфигурационному файлу vanessa-runner. + По умолчанию содержит значение "./tools/vrunner.json". + """) + String vrunnerSettings + + @JsonPropertyDescription("""Выполнять публикацию результатов в отчет Allure. + По умолчанию выключено. + """) + boolean publishToAllureReport + + @JsonPropertyDescription("""Выполнять публикацию результатов в отчет JUnit. + По умолчанию включено. + """) + boolean publishToJUnitReport + + @Override + @NonCPS + String toString() { + return "SyntaxCheckOptions{" + + "vrunnerSettings=" + vrunnerSettings + + ", publishToAllureReport=" + publishToAllureReport + + ", publishToJUnitReport=" + publishToJUnitReport + + '}'; + } +} diff --git a/src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy b/src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy index 2c6360d..8d55fe7 100644 --- a/src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy +++ b/src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy @@ -23,6 +23,9 @@ class PublishAllure implements Serializable { safeUnstash('init-allure') safeUnstash('bdd-allure') + if (config.smokeTestOptions.publishToAllureReport) { + safeUnstash(SmokeTest.SMOKE_ALLURE_STASH) + } def env = steps.env(); @@ -47,7 +50,7 @@ class PublishAllure implements Serializable { private void safeUnstash(String stashName) { try { steps.unstash(stashName) - } catch (Exception ex) { + } catch (Exception ignored) { Logger.println("Can't unstash $stashName") } } diff --git a/src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy b/src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy new file mode 100644 index 0000000..116fedb --- /dev/null +++ b/src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy @@ -0,0 +1,98 @@ +package ru.pulsar.jenkins.library.steps + +import hudson.FilePath +import ru.pulsar.jenkins.library.IStepExecutor +import ru.pulsar.jenkins.library.configuration.JobConfiguration +import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.utils.FileUtils +import ru.pulsar.jenkins.library.utils.Logger +import ru.pulsar.jenkins.library.utils.VRunner + +class SmokeTest implements Serializable { + + public static final String SMOKE_ALLURE_STASH = 'smoke-allure' + + private final JobConfiguration config; + + SmokeTest(JobConfiguration config) { + this.config = config + } + + def run() { + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + Logger.printLocation() + + if (!config.stageFlags.smoke) { + Logger.println("Smoke test step is disabled") + return + } + + List logosConfig = ["LOGOS_CONFIG=$config.logosConfig"] + steps.withEnv(logosConfig) { + steps.installLocalDependencies() + } + + def options = config.smokeTestOptions + def env = steps.env() + + String vrunnerPath = VRunner.getVRunnerPath() + String command = "$vrunnerPath xunit --ibconnection \"/F./build/ib\"" + + String vrunnerSettings = options.vrunnerSettings + if (steps.fileExists(vrunnerSettings)) { + command += " --settings $vrunnerSettings"; + } + + String xddTestRunnerPath = "./oscript_modules/add/xddTestRunner.epf" + if (steps.fileExists(xddTestRunnerPath)) { + command += " --pathxunit $xddTestRunnerPath" + } + + String xddConfigPath = "./tools/xUnitParams.json" + if (steps.fileExists(xddConfigPath)) { + command += " --xddConfig $xddConfigPath" + } + + String junitReport = "build/out/jUnit/smoke/smoke.xml" + FilePath pathToJUnitReport = FileUtils.getFilePath("$env.WORKSPACE/$junitReport") + String junitReportDir = FileUtils.getLocalPath(pathToJUnitReport.getParent()) + + steps.createDir(junitReportDir) + + String allureReport = "build/out/allure/smoke/allure.xml" + FilePath pathToAllureReport = FileUtils.getFilePath("$env.WORKSPACE/$allureReport") + String allureReportDir = FileUtils.getLocalPath(pathToAllureReport.getParent()) + + steps.createDir(allureReportDir) + + command += " --reportsxunit \"ГенераторОтчетаJUnitXML{$junitReport};ГенераторОтчетаAllureXMLВерсия2{$allureReport}\"" + if (steps.isUnix()) { + command = command.replace(';', '\\;') + } + + if (!VRunner.configContainsSetting(vrunnerSettings, "testsPath")) { + String testsPath = "oscript_modules/add/tests/smoke" + if (!steps.fileExists(testsPath)) { + testsPath = '$addRoot/tests/smoke' + if (steps.isUnix()) { + testsPath = '\\' + testsPath + } + } + command += " $testsPath" + } + + steps.withEnv(logosConfig) { + VRunner.exec(command) + } + + steps.stash(SMOKE_ALLURE_STASH, "$allureReportDir/**", true) + + if (options.publishToJUnitReport) { + steps.junit("$junitReportDir/*.xml", true) + } + + steps.archiveArtifacts("$junitReportDir/**") + steps.archiveArtifacts("$allureReportDir/**") + } +} diff --git a/src/ru/pulsar/jenkins/library/utils/VRunner.groovy b/src/ru/pulsar/jenkins/library/utils/VRunner.groovy index d9b48ab..f59b7fd 100644 --- a/src/ru/pulsar/jenkins/library/utils/VRunner.groovy +++ b/src/ru/pulsar/jenkins/library/utils/VRunner.groovy @@ -27,4 +27,11 @@ class VRunner { return steps.cmd(command, returnStatus) } as int } + + static boolean configContainsSetting(String configPath, String settingName) { + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + String fileContent = steps.readFile(configPath) + return fileContent.contains("\"$settingName\"") + } } diff --git a/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy b/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy index 7183967..74054aa 100644 --- a/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy +++ b/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy @@ -28,7 +28,7 @@ class VersionParser implements Serializable { return "" } - def configurationText = steps.readFile(filePath, 'UTF-8'); + def configurationText = steps.readFile(filePath); return version(configurationText, regexp) } diff --git a/vars/pipeline1C.groovy b/vars/pipeline1C.groovy index efab2c4..2314045 100644 --- a/vars/pipeline1C.groovy +++ b/vars/pipeline1C.groovy @@ -183,6 +183,8 @@ void call() { expression { config.stageFlags.smoke } } steps { + unzipInfobase() + smoke config } } diff --git a/vars/smoke.groovy b/vars/smoke.groovy index fc204f6..f43802f 100644 --- a/vars/smoke.groovy +++ b/vars/smoke.groovy @@ -1,23 +1,12 @@ import ru.pulsar.jenkins.library.configuration.JobConfiguration import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.steps.SmokeTest def call(JobConfiguration config) { ContextRegistry.registerDefaultContext(this) - // TODO: Вынести в отдельный класс по аналогии с SonarScanner - - printLocation() - - if (!config.stageFlags.smoke) { - echo("Smoke tests step is disabled") - return - } - - def options = config.syntaxCheckOptions - - installLocalDependencies() - - unzipInfobase() + def smokeTest = new SmokeTest(config) + smokeTest.run() }