1
0

Доработка Yaxunit (#13)

* 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
This commit is contained in:
Dima Ovcharenko
2023-07-06 21:38:34 +03:00
committed by Dima
parent 10310dd138
commit 37a219f8a9
10 changed files with 158 additions and 45 deletions

View File

@@ -61,6 +61,8 @@ dependencies {
integrationTestImplementation("org.slf4j", "slf4j-api", slf4jVersion) integrationTestImplementation("org.slf4j", "slf4j-api", slf4jVersion)
integrationTestImplementation("org.slf4j", "slf4j-simple", slf4jVersion) integrationTestImplementation("org.slf4j", "slf4j-simple", slf4jVersion)
integrationTestImplementation("org.springframework.security", "spring-security-core", "5.1.13.RELEASE")
} }
tasks.test { tasks.test {
@@ -105,6 +107,8 @@ sharedLibrary {
dependency("org.6wind.jenkins", "lockable-resources", "2.7") dependency("org.6wind.jenkins", "lockable-resources", "2.7")
dependency("ru.yandex.qatools.allure", "allure-jenkins-plugin", "2.28.1") dependency("ru.yandex.qatools.allure", "allure-jenkins-plugin", "2.28.1")
val declarativePluginsVersion = "1.6.0" val declarativePluginsVersion = "1.6.0"
dependency("org.jenkinsci.plugins", "pipeline-model-api", declarativePluginsVersion) 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-declarative-agent", "1.1.1")
dependency("org.jenkinsci.plugins", "pipeline-model-definition", declarativePluginsVersion) dependency("org.jenkinsci.plugins", "pipeline-model-definition", declarativePluginsVersion)

View File

@@ -83,7 +83,12 @@
"publishToJUnitReport": true "publishToJUnitReport": true
}, },
"yaxunit": { "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": { "resultsTransform": {
"removeSupport": true, "removeSupport": true,

View File

@@ -142,6 +142,10 @@
"type": "integer", "type": "integer",
"description": "Таймаут шага дымовых тестов, в минутах.\n По умолчанию содержит значение 240.\n " "description": "Таймаут шага дымовых тестов, в минутах.\n По умолчанию содержит значение 240.\n "
}, },
"yaxunit": {
"type": "integer",
"description": "Таймаут шага Юнит тестов, в минутах.\n По умолчанию содержит значение 240.\n "
},
"sonarqube": { "sonarqube": {
"type": "integer", "type": "integer",
"description": "Таймаут шага статического анализа SonarQube, в минутах.\n По умолчанию содержит значение 90.\n " "description": "Таймаут шага статического анализа SonarQube, в минутах.\n По умолчанию содержит значение 90.\n "
@@ -305,7 +309,15 @@
}, },
"configPath": { "configPath": {
"type": "string", "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 "
} }
} }
}, },

26
resources/yaxunit.json Normal file
View File

@@ -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"
}

View File

@@ -65,7 +65,7 @@ class ConfigurationReader implements Serializable {
"bddOptions", "bddOptions",
"sonarQubeOptions", "sonarQubeOptions",
"smokeTestOptions", "smokeTestOptions",
"yaxunitoptions", "yaxunitOptions",
"syntaxCheckOptions", "syntaxCheckOptions",
"resultsTransformOptions", "resultsTransformOptions",
"notificationsOptions", "notificationsOptions",
@@ -81,6 +81,7 @@ class ConfigurationReader implements Serializable {
mergeObjects(baseConfiguration, configurationToMerge, nonMergeableSettings) mergeObjects(baseConfiguration, configurationToMerge, nonMergeableSettings)
mergeInitInfoBaseOptions(baseConfiguration.initInfoBaseOptions, configurationToMerge.initInfoBaseOptions) mergeInitInfoBaseOptions(baseConfiguration.initInfoBaseOptions, configurationToMerge.initInfoBaseOptions)
mergeBddOptions(baseConfiguration.bddOptions, configurationToMerge.bddOptions) mergeBddOptions(baseConfiguration.bddOptions, configurationToMerge.bddOptions)
mergeYaxunitOptions(baseConfiguration.yaxunitOptions, configurationToMerge.yaxunitOptions)
mergeSyntaxCheckOptions(baseConfiguration.syntaxCheckOptions, configurationToMerge.syntaxCheckOptions) mergeSyntaxCheckOptions(baseConfiguration.syntaxCheckOptions, configurationToMerge.syntaxCheckOptions)
mergeNotificationsOptions(baseConfiguration.notificationsOptions, configurationToMerge.notificationsOptions) mergeNotificationsOptions(baseConfiguration.notificationsOptions, configurationToMerge.notificationsOptions)
@@ -147,6 +148,14 @@ class ConfigurationReader implements Serializable {
baseObject.vrunnerSteps = objectToMerge.vrunnerSteps.clone() 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 @NonCPS
private static void mergeSyntaxCheckOptions(SyntaxCheckOptions baseObject, SyntaxCheckOptions objectToMerge) { private static void mergeSyntaxCheckOptions(SyntaxCheckOptions baseObject, SyntaxCheckOptions objectToMerge) {
if (objectToMerge == null || objectToMerge.checkModes == null) { if (objectToMerge == null || objectToMerge.checkModes == null) {

View File

@@ -88,7 +88,7 @@ class JobConfiguration implements Serializable {
", sonarQubeOptions=" + sonarQubeOptions + ", sonarQubeOptions=" + sonarQubeOptions +
", syntaxCheckOptions=" + syntaxCheckOptions + ", syntaxCheckOptions=" + syntaxCheckOptions +
", smokeTestOptions=" + smokeTestOptions + ", smokeTestOptions=" + smokeTestOptions +
", yaxunitoptions=" + yaxunitOptions + ", yaxunitOptions=" + yaxunitOptions +
", resultsTransformOptions=" + resultsTransformOptions + ", resultsTransformOptions=" + resultsTransformOptions +
", notificationOptions=" + notificationsOptions + ", notificationOptions=" + notificationsOptions +
", logosConfig='" + logosConfig + '\'' + ", logosConfig='" + logosConfig + '\'' +

View File

@@ -10,13 +10,40 @@ class YaxunitOptions implements Serializable {
@JsonPropertyDescription("""Путь к конфигурационному файлу vanessa-runner. @JsonPropertyDescription("""Путь к конфигурационному файлу vanessa-runner.
По умолчанию содержит значение "./tools/vrunner.json". По умолчанию содержит значение "./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 @Override
@NonCPS @NonCPS
String toString() { String toString() {
return "YaxunitTestOptions{" + return "YaxunitTestOptions{" +
"vrunnerSettings='" + vrunnerSettings + '\'' + "vrunnerSettings='" + vrunnerSettings + '\'' +
", cfe='" + cfe +
", extensionNames='" + extensionNames.toString() +
", configPath='" + configPath + ", configPath='" + configPath +
'}' '}'
} }

View File

@@ -9,8 +9,8 @@ import ru.pulsar.jenkins.library.utils.Logger
class PublishAllure implements Serializable { class PublishAllure implements Serializable {
private final JobConfiguration config; private final JobConfiguration config
private IStepExecutor steps; private IStepExecutor steps
PublishAllure(JobConfiguration config) { PublishAllure(JobConfiguration config) {
this.config = config this.config = config
@@ -33,11 +33,14 @@ class PublishAllure implements Serializable {
if (config.stageFlags.bdd) { if (config.stageFlags.bdd) {
safeUnstash('bdd-allure') safeUnstash('bdd-allure')
} }
if (config.stageFlags.yaxunit) {
safeUnstash(Yaxunit.YAXUNIT_ALLURE_STASH)
}
if (config.stageFlags.smoke && config.smokeTestOptions.publishToAllureReport) { if (config.stageFlags.smoke && config.smokeTestOptions.publishToAllureReport) {
safeUnstash(SmokeTest.SMOKE_ALLURE_STASH) safeUnstash(SmokeTest.SMOKE_ALLURE_STASH)
} }
def env = steps.env(); def env = steps.env()
FilePath allurePath = FileUtils.getFilePath("$env.WORKSPACE/build/out/allure") FilePath allurePath = FileUtils.getFilePath("$env.WORKSPACE/build/out/allure")
if (!allurePath.exists()) { if (!allurePath.exists()) {
@@ -45,7 +48,7 @@ class PublishAllure implements Serializable {
return return
} }
List<String> results = new ArrayList<>(); List<String> results = new ArrayList<>()
allurePath.listDirectories().each { FilePath filePath -> allurePath.listDirectories().each { FilePath filePath ->
results.add(FileUtils.getLocalPath(filePath)) results.add(FileUtils.getLocalPath(filePath))

View File

@@ -8,14 +8,16 @@ import ru.pulsar.jenkins.library.utils.FileUtils
import ru.pulsar.jenkins.library.utils.Logger import ru.pulsar.jenkins.library.utils.Logger
import ru.pulsar.jenkins.library.utils.VRunner import ru.pulsar.jenkins.library.utils.VRunner
import java.nio.file.Files
class Yaxunit implements Serializable { class Yaxunit implements Serializable {
private final JobConfiguration config private final JobConfiguration config
private final String yaxunitPath = 'build/yaxunit.cfe' 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) { Yaxunit(JobConfiguration config) {
this.config = config this.config = config
} }
@@ -39,60 +41,85 @@ class Yaxunit implements Serializable {
def env = steps.env() def env = steps.env()
String vrunnerPath = VRunner.getVRunnerPath() String vrunnerPath = VRunner.getVRunnerPath()
String ibConnection = "--ibconnection /F./build/ib" String ibConnection = ' --ibconnection "/F./build/ib"'
// Скачиваем расширение с гитхаба // Скачиваем расширение
String pathToYaxunit = "$env.WORKSPACE/$yaxunitPath" String pathToYaxunit = "$env.WORKSPACE/$yaxunitPath"
FilePath localPathToYaxunit = FileUtils.getFilePath(pathToYaxunit) FilePath localPathToYaxunit = FileUtils.getFilePath(pathToYaxunit)
Logger.println("Скачивание Yaxunit в $localPathToYaxunit") 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))
// Устанавливаем расширение // Команда загрузки YAXUnit
// String loadYaxunitCommand = "$vrunnerPath loadext -f $localPathToYaxunit --extension Yaxunit --updatedb $ibConnection" String loadYaxunitCommand = vrunnerPath + ' run --command "Путь=' + pathToYaxunit + ';ЗавершитьРаботуСистемы;" --execute '
String loadYaxunitCommand = vrunnerPath + ' run --command "Путь=' + pathToYaxunit + ';ЗавершитьРаботуСистемы" --execute $runnerRoot/epf/ЗагрузитьРасширениеВРежимеПредприятия.epf ' + ibConnection String executeParameter = '$runnerRoot/epf/ЗагрузитьРасширениеВРежимеПредприятия.epf'
// Устанавливаем тесты if (steps.isUnix()) {
String loadTestsCommand = "$vrunnerPath compileext ./src/cfe test --updatedb $ibConnection" executeParameter = '\\' + executeParameter
}
loadYaxunitCommand += executeParameter
loadYaxunitCommand += ' --ibconnection "/F./build/ib"'
// Создаем конфиг, т.к. в репо может быть ключ, который не закрывает программу и может повесить конвеер // Команда сборки расширений с тестами и их загрузки в ИБ
// Также путь к отчету в формате junit указывается в конфиге, т.к. мы не знаем на чем стартует агент, def loadTestExtCommands = []
// поэтому собираем сами. Стоит вынести в отдельный класс for (String extension in options.extensionNames) {
String junitReport = "build/out/jUnit/yaxunit/yaxunit.xml" if (extension == "YAXUNIT") {
FilePath pathToJUnitReport = FileUtils.getFilePath("$env.WORKSPACE/$junitReport") continue
String junitReportDir = FileUtils.getLocalPath(pathToJUnitReport.getParent()) }
String configYaxunit = "test-config.json" def loadTestExtCommand = "$vrunnerPath compileext ./src/cfe/$extension $extension --updatedb $ibConnection"
FilePath pathToConfig = FileUtils.getFilePath("$env.WORKSPACE/$configYaxunit") loadTestExtCommands << loadTestExtCommand
// def data = [ Logger.println("Команда сборки расширения: $loadTestExtCommands")
// '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()))
// Запускаем тесты String yaxunitConfigPath = options.configPath
String command = "$vrunnerPath run --command RunUnitTests=$pathToConfig $ibConnection" 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 vrunnerSettings = options.vrunnerSettings
String[] loadTestExtCommandJoined = loadTestExtCommands
if (steps.fileExists(vrunnerSettings)) { if (steps.fileExists(vrunnerSettings)) {
String vrunnerSettingsCommand = " --settings $vrunnerSettings" String vrunnerSettingsCommand = " --settings $vrunnerSettings"
command += vrunnerSettingsCommand
loadYaxunitCommand += vrunnerSettingsCommand loadYaxunitCommand += vrunnerSettingsCommand
loadTestsCommand += vrunnerSettingsCommand
loadTestExtCommandJoined = loadTestExtCommands.collect { "$it $vrunnerSettingsCommand" }
command += vrunnerSettingsCommand
} }
// Выполяем команды
steps.withEnv(logosConfig) { steps.withEnv(logosConfig) {
VRunner.exec(loadYaxunitCommand, true) VRunner.exec(loadYaxunitCommand, true)
VRunner.exec(loadTestsCommand, true) for (loadTestExtCommand in loadTestExtCommandJoined) {
VRunner.exec(loadTestExtCommand, true)
}
VRunner.exec(command, true) VRunner.exec(command, true)
} }
// Сохраняем результаты // Сохраняем результаты
steps.junit("$junitReportDir/*.xml", true) String junitReport = "./build/out/yaxunit/junit.xml"
steps.archiveArtifacts("$junitReportDir/**") 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)
}
} }
} }

View File

@@ -253,7 +253,7 @@ void call() {
expression { config.stageFlags.yaxunit } expression { config.stageFlags.yaxunit }
} }
steps { steps {
timeout(time: config.timeoutOptions.smoke, unit: TimeUnit.MINUTES) { timeout(time: config.timeoutOptions.yaxunit, unit: TimeUnit.MINUTES) {
unzipInfobase() unzipInfobase()
yaxunit config yaxunit config