From 37a219f8a9c905518a4525dce1f27c38bad98949 Mon Sep 17 00:00:00 2001 From: Dima Ovcharenko Date: Thu, 6 Jul 2023 21:38:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20Yaxunit=20(#13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add params * rewrite and add params * fix options merge * fix command * switch to ArrayList * fix junit reports * fix yaxunit config * fix yaxunit config * fix yaxunit config paths * add allure * fix allure * fix public * fix static * copy allure * publish options * schema upd --- build.gradle.kts | 4 + resources/globalConfiguration.json | 7 +- resources/schema.json | 14 ++- resources/yaxunit.json | 26 +++++ .../configuration/ConfigurationReader.groovy | 11 ++- .../configuration/JobConfiguration.groovy | 2 +- .../configuration/YaxunitOptions.groovy | 29 +++++- .../library/steps/PublishAllure.groovy | 11 ++- .../jenkins/library/steps/Yaxunit.groovy | 97 ++++++++++++------- vars/pipeline1C.groovy | 2 +- 10 files changed, 158 insertions(+), 45 deletions(-) create mode 100644 resources/yaxunit.json diff --git a/build.gradle.kts b/build.gradle.kts index 2de8c20..e557c92 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -61,6 +61,8 @@ dependencies { integrationTestImplementation("org.slf4j", "slf4j-api", slf4jVersion) integrationTestImplementation("org.slf4j", "slf4j-simple", slf4jVersion) + integrationTestImplementation("org.springframework.security", "spring-security-core", "5.1.13.RELEASE") + } tasks.test { @@ -105,6 +107,8 @@ sharedLibrary { dependency("org.6wind.jenkins", "lockable-resources", "2.7") dependency("ru.yandex.qatools.allure", "allure-jenkins-plugin", "2.28.1") val declarativePluginsVersion = "1.6.0" + + dependency("org.jenkinsci.plugins", "pipeline-model-api", declarativePluginsVersion) dependency("org.jenkinsci.plugins", "pipeline-model-declarative-agent", "1.1.1") dependency("org.jenkinsci.plugins", "pipeline-model-definition", declarativePluginsVersion) diff --git a/resources/globalConfiguration.json b/resources/globalConfiguration.json index c7d9078..fffe032 100644 --- a/resources/globalConfiguration.json +++ b/resources/globalConfiguration.json @@ -83,7 +83,12 @@ "publishToJUnitReport": true }, "yaxunit": { - "vrunnerSettings": "./tools/vrunner.json" + "vrunnerSettings": "./tools/vrunner.json", + "cfe": "https://github.com/bia-technologies/yaxunit/releases/download/23.05/YAXUNIT-23.05.cfe", + "extensionNames": ["YAXUNIT"], + "configPath": "./tools/yaxunit.json", + "publishToAllureReport": false, + "publishToJUnitReport": true }, "resultsTransform": { "removeSupport": true, diff --git a/resources/schema.json b/resources/schema.json index 4636277..acc82d0 100644 --- a/resources/schema.json +++ b/resources/schema.json @@ -142,6 +142,10 @@ "type": "integer", "description": "Таймаут шага дымовых тестов, в минутах.\n По умолчанию содержит значение 240.\n " }, + "yaxunit": { + "type": "integer", + "description": "Таймаут шага Юнит тестов, в минутах.\n По умолчанию содержит значение 240.\n " + }, "sonarqube": { "type": "integer", "description": "Таймаут шага статического анализа SonarQube, в минутах.\n По умолчанию содержит значение 90.\n " @@ -305,7 +309,15 @@ }, "configPath": { "type": "string", - "description": "Путь к конфигурационному файлу для Yaxunit.\n По умолчанию содержит значение \"./tools/YaxunitConfig.json\".\n " + "description": "Путь к конфигурационному файлу YAXUnit.\n По умолчанию содержит значение \"./tools/yaxunit.json\".\n " + }, + "publishToAllureReport": { + "type": "boolean", + "description": "Выполнять публикацию результатов в отчет Allure.\n По умолчанию выключено.\n " + }, + "publishToJUnitReport": { + "type": "boolean", + "description": "Выполнять публикацию результатов в отчет JUnit.\n По умолчанию включено.\n " } } }, diff --git a/resources/yaxunit.json b/resources/yaxunit.json new file mode 100644 index 0000000..b591045 --- /dev/null +++ b/resources/yaxunit.json @@ -0,0 +1,26 @@ +{ + "reportPath": "./build/out/yaxunit/junit.xml", + "closeAfterTests": true, + "filter": { + "extensions": [ + "YAXUNIT" + ], + "modules": null, + "suites": null, + "tags": null, + "contexts": null, + "paths": null, + "tests": null + }, + "settings": { + "ВТранзакции": true + }, + "reportFormat": "jUnit", + "showReport": false, + "logging": { + "file": "./build/out/yaxunit/log.txt", + "enable": false, + "level": "debug" + }, + "exitCode": "./build/out/yaxunit/result.txt" +} \ No newline at end of file diff --git a/src/ru/pulsar/jenkins/library/configuration/ConfigurationReader.groovy b/src/ru/pulsar/jenkins/library/configuration/ConfigurationReader.groovy index 94099c4..7b28579 100644 --- a/src/ru/pulsar/jenkins/library/configuration/ConfigurationReader.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/ConfigurationReader.groovy @@ -65,7 +65,7 @@ class ConfigurationReader implements Serializable { "bddOptions", "sonarQubeOptions", "smokeTestOptions", - "yaxunitoptions", + "yaxunitOptions", "syntaxCheckOptions", "resultsTransformOptions", "notificationsOptions", @@ -81,6 +81,7 @@ class ConfigurationReader implements Serializable { mergeObjects(baseConfiguration, configurationToMerge, nonMergeableSettings) mergeInitInfoBaseOptions(baseConfiguration.initInfoBaseOptions, configurationToMerge.initInfoBaseOptions) mergeBddOptions(baseConfiguration.bddOptions, configurationToMerge.bddOptions) + mergeYaxunitOptions(baseConfiguration.yaxunitOptions, configurationToMerge.yaxunitOptions) mergeSyntaxCheckOptions(baseConfiguration.syntaxCheckOptions, configurationToMerge.syntaxCheckOptions) mergeNotificationsOptions(baseConfiguration.notificationsOptions, configurationToMerge.notificationsOptions) @@ -147,6 +148,14 @@ class ConfigurationReader implements Serializable { baseObject.vrunnerSteps = objectToMerge.vrunnerSteps.clone() } + @NonCPS + private static void mergeYaxunitOptions(YaxunitOptions baseObject, YaxunitOptions objectToMerge) { + if (objectToMerge == null || objectToMerge.extensionNames == null) { + return + } + baseObject.extensionNames = objectToMerge.extensionNames.clone() + } + @NonCPS private static void mergeSyntaxCheckOptions(SyntaxCheckOptions baseObject, SyntaxCheckOptions objectToMerge) { if (objectToMerge == null || objectToMerge.checkModes == null) { diff --git a/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy b/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy index dca45a0..72a008c 100644 --- a/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy @@ -88,7 +88,7 @@ class JobConfiguration implements Serializable { ", sonarQubeOptions=" + sonarQubeOptions + ", syntaxCheckOptions=" + syntaxCheckOptions + ", smokeTestOptions=" + smokeTestOptions + - ", yaxunitoptions=" + yaxunitOptions + + ", yaxunitOptions=" + yaxunitOptions + ", resultsTransformOptions=" + resultsTransformOptions + ", notificationOptions=" + notificationsOptions + ", logosConfig='" + logosConfig + '\'' + diff --git a/src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy b/src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy index 83e7be8..2c8e357 100644 --- a/src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/YaxunitOptions.groovy @@ -10,13 +10,40 @@ class YaxunitOptions implements Serializable { @JsonPropertyDescription("""Путь к конфигурационному файлу vanessa-runner. По умолчанию содержит значение "./tools/vrunner.json". """) - String vrunnerSettings + String vrunnerSettings = "./tools/vrunner.json" + + @JsonPropertyDescription("""Ссылка на скачивание YAXUnit. + По умолчанию содержит ссылку на официальный релиз версии 23.05. + """) + String cfe = "https://github.com/bia-technologies/yaxunit/releases/download/23.05/YAXUNIT-23.05.cfe" + + @JsonPropertyDescription("""Имена расширений с тестами. + По умолчанию содержит один элемент - YAXUNIT. + """) + String[] extensionNames = ['YAXUNIT'] + + @JsonPropertyDescription("""Путь к конфигурационному файлу YAXUnit. + По умолчанию содержит значение "./tools/yaxunit.json". + """) + String configPath = "./tools/yaxunit.json" + + @JsonPropertyDescription("""Выполнять публикацию результатов в отчет Allure. + По умолчанию выключено. + """) + boolean publishToAllureReport + + @JsonPropertyDescription("""Выполнять публикацию результатов в отчет JUnit. + По умолчанию включено. + """) + boolean publishToJUnitReport @Override @NonCPS String toString() { return "YaxunitTestOptions{" + "vrunnerSettings='" + vrunnerSettings + '\'' + + ", cfe='" + cfe + + ", extensionNames='" + extensionNames.toString() + ", configPath='" + configPath + '}' } diff --git a/src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy b/src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy index aaf7046..e7c0e97 100644 --- a/src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy +++ b/src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy @@ -9,8 +9,8 @@ import ru.pulsar.jenkins.library.utils.Logger class PublishAllure implements Serializable { - private final JobConfiguration config; - private IStepExecutor steps; + private final JobConfiguration config + private IStepExecutor steps PublishAllure(JobConfiguration config) { this.config = config @@ -33,11 +33,14 @@ class PublishAllure implements Serializable { if (config.stageFlags.bdd) { safeUnstash('bdd-allure') } + if (config.stageFlags.yaxunit) { + safeUnstash(Yaxunit.YAXUNIT_ALLURE_STASH) + } if (config.stageFlags.smoke && config.smokeTestOptions.publishToAllureReport) { safeUnstash(SmokeTest.SMOKE_ALLURE_STASH) } - def env = steps.env(); + def env = steps.env() FilePath allurePath = FileUtils.getFilePath("$env.WORKSPACE/build/out/allure") if (!allurePath.exists()) { @@ -45,7 +48,7 @@ class PublishAllure implements Serializable { return } - List results = new ArrayList<>(); + List results = new ArrayList<>() allurePath.listDirectories().each { FilePath filePath -> results.add(FileUtils.getLocalPath(filePath)) diff --git a/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy b/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy index 943bfe1..bbf98c8 100644 --- a/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy +++ b/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy @@ -8,14 +8,16 @@ import ru.pulsar.jenkins.library.utils.FileUtils import ru.pulsar.jenkins.library.utils.Logger import ru.pulsar.jenkins.library.utils.VRunner -import java.nio.file.Files - class Yaxunit implements Serializable { private final JobConfiguration config private final String yaxunitPath = 'build/yaxunit.cfe' + private final String DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE = 'yaxunit.json' + + public static final String YAXUNIT_ALLURE_STASH = 'yaxunit-allure' + Yaxunit(JobConfiguration config) { this.config = config } @@ -39,60 +41,85 @@ class Yaxunit implements Serializable { def env = steps.env() String vrunnerPath = VRunner.getVRunnerPath() - String ibConnection = "--ibconnection /F./build/ib" + String ibConnection = ' --ibconnection "/F./build/ib"' - // Скачиваем расширение с гитхаба + // Скачиваем расширение String pathToYaxunit = "$env.WORKSPACE/$yaxunitPath" FilePath localPathToYaxunit = FileUtils.getFilePath(pathToYaxunit) Logger.println("Скачивание Yaxunit в $localPathToYaxunit") - localPathToYaxunit.copyFrom(new URL('https://github.com/bia-technologies/yaxunit/releases/download/22.11.0/YAXUNIT-22.11.cfe')) + localPathToYaxunit.copyFrom(new URL(options.cfe)) - // Устанавливаем расширение -// String loadYaxunitCommand = "$vrunnerPath loadext -f $localPathToYaxunit --extension Yaxunit --updatedb $ibConnection" - String loadYaxunitCommand = vrunnerPath + ' run --command "Путь=' + pathToYaxunit + ';ЗавершитьРаботуСистемы" --execute $runnerRoot/epf/ЗагрузитьРасширениеВРежимеПредприятия.epf ' + ibConnection - // Устанавливаем тесты - String loadTestsCommand = "$vrunnerPath compileext ./src/cfe test --updatedb $ibConnection" + // Команда загрузки YAXUnit + String loadYaxunitCommand = vrunnerPath + ' run --command "Путь=' + pathToYaxunit + ';ЗавершитьРаботуСистемы;" --execute ' + String executeParameter = '$runnerRoot/epf/ЗагрузитьРасширениеВРежимеПредприятия.epf' + if (steps.isUnix()) { + executeParameter = '\\' + executeParameter + } + loadYaxunitCommand += executeParameter + loadYaxunitCommand += ' --ibconnection "/F./build/ib"' - // Создаем конфиг, т.к. в репо может быть ключ, который не закрывает программу и может повесить конвеер - // Также путь к отчету в формате junit указывается в конфиге, т.к. мы не знаем на чем стартует агент, - // поэтому собираем сами. Стоит вынести в отдельный класс - String junitReport = "build/out/jUnit/yaxunit/yaxunit.xml" - FilePath pathToJUnitReport = FileUtils.getFilePath("$env.WORKSPACE/$junitReport") - String junitReportDir = FileUtils.getLocalPath(pathToJUnitReport.getParent()) - String configYaxunit = "test-config.json" - FilePath pathToConfig = FileUtils.getFilePath("$env.WORKSPACE/$configYaxunit") -// def data = [ -// 'filter' : 'test', -// 'reportPath' : 'ss' -// ] -// String data = "{\"filter\": {\"extensions\": [\"test\"]}, \"reportPath\": \"$pathToConfig\"}" -// def json = new groovy.json.JsonBuilder() -// json "filter" : "jj", "reportPath" : "ii" -// def file = new File("$env.WORKSPACE\\$configYaxunit") -// file.createNewFile() -// file.write(groovy.json.JsonOutput.prettyPrint(json.toString())) + // Команда сборки расширений с тестами и их загрузки в ИБ + def loadTestExtCommands = [] + for (String extension in options.extensionNames) { + if (extension == "YAXUNIT") { + continue + } + def loadTestExtCommand = "$vrunnerPath compileext ./src/cfe/$extension $extension --updatedb $ibConnection" + loadTestExtCommands << loadTestExtCommand + Logger.println("Команда сборки расширения: $loadTestExtCommands") + } - // Запускаем тесты - String command = "$vrunnerPath run --command RunUnitTests=$pathToConfig $ibConnection" + String yaxunitConfigPath = options.configPath + File yaxunitConfigFile = new File("$env.WORKSPACE/$yaxunitConfigPath") + if (!steps.fileExists(yaxunitConfigPath)) { + def defaultYaxunitConfig = steps.libraryResource DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE + yaxunitConfigFile.write defaultYaxunitConfig + } + def yaxunitConfig = yaxunitConfigFile.getCanonicalPath() + // Команда запуска тестов + String command = "$vrunnerPath run --command RunUnitTests=$yaxunitConfig $ibConnection" + + // Переопределяем настройки vrunner String vrunnerSettings = options.vrunnerSettings + String[] loadTestExtCommandJoined = loadTestExtCommands if (steps.fileExists(vrunnerSettings)) { String vrunnerSettingsCommand = " --settings $vrunnerSettings" - command += vrunnerSettingsCommand loadYaxunitCommand += vrunnerSettingsCommand - loadTestsCommand += vrunnerSettingsCommand + + loadTestExtCommandJoined = loadTestExtCommands.collect { "$it $vrunnerSettingsCommand" } + command += vrunnerSettingsCommand + } + // Выполяем команды steps.withEnv(logosConfig) { VRunner.exec(loadYaxunitCommand, true) - VRunner.exec(loadTestsCommand, true) + for (loadTestExtCommand in loadTestExtCommandJoined) { + VRunner.exec(loadTestExtCommand, true) + } VRunner.exec(command, true) } // Сохраняем результаты - steps.junit("$junitReportDir/*.xml", true) - steps.archiveArtifacts("$junitReportDir/**") + String junitReport = "./build/out/yaxunit/junit.xml" + FilePath pathToJUnitReport = FileUtils.getFilePath("$env.WORKSPACE/$junitReport") + String junitReportDir = FileUtils.getLocalPath(pathToJUnitReport.getParent()) + if (options.publishToJUnitReport) { + steps.junit("$junitReportDir/*.xml", true) + steps.archiveArtifacts("$junitReportDir/**") + } + + if (options.publishToAllureReport) { + String allureReport = "./build/out/allure/yaxunit/junit.xml" + FilePath pathToAllureReport = FileUtils.getFilePath("$env.WORKSPACE/$allureReport") + String allureReportDir = FileUtils.getLocalPath(pathToAllureReport.getParent()) + + pathToJUnitReport.copyTo(pathToAllureReport) + + steps.stash(YAXUNIT_ALLURE_STASH, "$allureReportDir/**", true) + } } } diff --git a/vars/pipeline1C.groovy b/vars/pipeline1C.groovy index 76df555..6fdc856 100644 --- a/vars/pipeline1C.groovy +++ b/vars/pipeline1C.groovy @@ -253,7 +253,7 @@ void call() { expression { config.stageFlags.yaxunit } } steps { - timeout(time: config.timeoutOptions.smoke, unit: TimeUnit.MINUTES) { + timeout(time: config.timeoutOptions.yaxunit, unit: TimeUnit.MINUTES) { unzipInfobase() yaxunit config