diff --git a/resources/globalConfiguration.json b/resources/globalConfiguration.json index 332119d..cf5a9c6 100644 --- a/resources/globalConfiguration.json +++ b/resources/globalConfiguration.json @@ -6,11 +6,16 @@ "storage": "UNKNOWN_ID" }, "stages": { + "initSteps": false, "sonarqube": false, "syntaxCheck": false, "edtValidate": false, "smoke": false }, + "initInfobase": { + "runMigration": true, + "additionalMigrationSteps": [] + }, "sonarqube": { "sonarQubeInstallation": "", "useSonarScannerFromPath": true, diff --git a/resources/schema.json b/resources/schema.json index 40bcd1c..df6a028 100644 --- a/resources/schema.json +++ b/resources/schema.json @@ -45,6 +45,28 @@ "smoke" : { "type" : "boolean", "description" : "Дымовые тесты включены" + }, + "initSteps" : { + "type" : "boolean", + "description" : "Предварительные шаги инициализации включены" + } + } + }, + "initInfobase" : { + "type" : "object", + "id" : "urn:jsonschema:ru:pulsar:jenkins:library:configuration:InitInfobaseOptions", + "description" : "Настройки шага инициализации ИБ", + "properties" : { + "runMigration" : { + "type" : "boolean", + "description" : "Запустить миграцию ИБ" + }, + "additionalMigrationSteps" : { + "type" : "array", + "description" : "Дополнительные шаги, запускаемые через vrunner.\n В каждой строке передается отдельная команда \n vrunner и ее аргументы (например, \"vanessa --settings ./tools/vrunner.first.json\")\n ", + "items" : { + "type" : "string" + } } } }, diff --git a/src/ru/pulsar/jenkins/library/configuration/ConfigurationReader.groovy b/src/ru/pulsar/jenkins/library/configuration/ConfigurationReader.groovy index d17ddf5..1e2bcca 100644 --- a/src/ru/pulsar/jenkins/library/configuration/ConfigurationReader.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/ConfigurationReader.groovy @@ -41,12 +41,14 @@ class ConfigurationReader implements Serializable { def nonMergeableSettings = Arrays.asList( "secrets", "stageFlags", + "initInfobaseOptions", "sonarQubeOptions", "syntaxCheckOptions", "resultsTransformOptions" ).toSet() mergeObjects(baseConfiguration, configurationToMerge, nonMergeableSettings) + mergeInitInfobaseOptions(baseConfiguration.initInfobaseOptions, configurationToMerge.initInfobaseOptions); return baseConfiguration; } @@ -70,4 +72,9 @@ class ConfigurationReader implements Serializable { ) }) } + + @NonCPS + private static void mergeInitInfobaseOptions(InitInfobaseOptions baseObject, InitInfobaseOptions objectToMerge) { + baseObject.additionalMigrationSteps = objectToMerge.additionalMigrationSteps.clone() + } } diff --git a/src/ru/pulsar/jenkins/library/configuration/InitInfobaseOptions.groovy b/src/ru/pulsar/jenkins/library/configuration/InitInfobaseOptions.groovy new file mode 100644 index 0000000..80f6b66 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/configuration/InitInfobaseOptions.groovy @@ -0,0 +1,27 @@ +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 InitInfobaseOptions implements Serializable { + + @JsonPropertyDescription("Запустить миграцию ИБ") + boolean runMigration = true + + @JsonPropertyDescription("""Дополнительные шаги, запускаемые через vrunner. + В каждой строке передается отдельная команда + vrunner и ее аргументы (например, "vanessa --settings ./tools/vrunner.first.json") + """) + String[] additionalMigrationSteps + + @Override + @NonCPS + String toString() { + return "InitInfobaseOptions{" + + "runMigration=" + runMigration + + ", additionalMigrationSteps=" + additionalMigrationSteps + + '}'; + } +} diff --git a/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy b/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy index 3368d8e..87e23b3 100644 --- a/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/JobConfiguration.groovy @@ -20,6 +20,10 @@ class JobConfiguration implements Serializable { @JsonPropertyDescription("Идентификаторы сохраненных секретов") Secrets secrets; + @JsonProperty("initInfobase") + @JsonPropertyDescription("Настройки шага инициализации ИБ") + InitInfobaseOptions initInfobaseOptions; + @JsonProperty("sonarqube") @JsonPropertyDescription("Настройки анализа SonarQube") SonarQubeOptions sonarQubeOptions; @@ -40,6 +44,7 @@ class JobConfiguration implements Serializable { ", srcDir='" + srcDir + '\'' + ", stageFlags=" + stageFlags + ", secrets=" + secrets + + ", initInfobaseOptions=" + initInfobaseOptions + ", sonarQubeOptions=" + sonarQubeOptions + ", syntaxCheckOptions=" + syntaxCheckOptions + ", resultsTransformOptions=" + resultsTransformOptions + diff --git a/src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy b/src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy index c73a158..042aab2 100644 --- a/src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy @@ -18,6 +18,9 @@ class StageFlags implements Serializable { @JsonPropertyDescription("Дымовые тесты включены") boolean smoke + @JsonPropertyDescription("Предварительные шаги инициализации включены") + boolean initSteps + @Override @NonCPS String toString() { @@ -26,10 +29,11 @@ class StageFlags implements Serializable { ", syntaxCheck=" + syntaxCheck + ", edtValidate=" + edtValidate + ", smoke=" + smoke + + ", initSteps=" + initSteps + '}'; } boolean needInfobase() { - return smoke || syntaxCheck + return smoke || syntaxCheck || initSteps } } diff --git a/src/ru/pulsar/jenkins/library/steps/InitInfobase.groovy b/src/ru/pulsar/jenkins/library/steps/InitInfobase.groovy new file mode 100644 index 0000000..09e1a43 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/steps/InitInfobase.groovy @@ -0,0 +1,40 @@ +package ru.pulsar.jenkins.library.steps + +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.Logger + +class InitInfobase implements Serializable { + + private final JobConfiguration config; + + InitInfobase(JobConfiguration config) { + this.config = config + } + + def run() { + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + Logger.printLocation() + + if (!config.stageFlags.initSteps) { + Logger.println("Init step is disabled") + return + } + + if (config.initInfobaseOptions.runMigration) { + Logger.println("Запуск миграции ИБ") + + // Запуск миграции + steps.cmd("oscript_modules/bin/vrunner run --command \"ЗапуститьОбновлениеИнформационнойБазы;ЗавершитьРаботуСистемы;\" --execute \$runnerRoot/epf/ЗакрытьПредприятие.epf --ibconnection \"/F./build/ib\"") + } else { + Logger.println("Шаг миграции ИБ выключен") + } + + config.initInfobaseOptions.additionalMigrationSteps.each { + Logger.println("Первичная инициализация командой ${it}") + steps.cmd("oscript_modules/bin/vrunner ${it}") + } + } +} diff --git a/test/unit/groovy/ru/pulsar/jenkins/library/configuration/ConfigurationReaderTest.java b/test/unit/groovy/ru/pulsar/jenkins/library/configuration/ConfigurationReaderTest.java index 01e4edc..d0be9f1 100644 --- a/test/unit/groovy/ru/pulsar/jenkins/library/configuration/ConfigurationReaderTest.java +++ b/test/unit/groovy/ru/pulsar/jenkins/library/configuration/ConfigurationReaderTest.java @@ -31,14 +31,21 @@ class ConfigurationReaderTest { // then assertThat(jobConfiguration.getV8version()).isEqualTo("8.3.14.1944"); + assertThat(jobConfiguration.getSonarQubeOptions().getSonarScannerToolName()).isEqualTo("sonar-scanner"); + assertThat(jobConfiguration.getSecrets()) .hasFieldOrPropertyWithValue("storage", "1234") .hasFieldOrPropertyWithValue("storagePath", "UNKNOWN_ID") ; + assertThat(jobConfiguration.getSyntaxCheckOptions().getCheckModes()).hasSize(1); + assertThat(jobConfiguration.getResultsTransformOptions().isRemoveSupport()).isTrue(); - assertThat(jobConfiguration.getResultsTransformOptions().getSupportLevel()).isEqualTo(0); + assertThat(jobConfiguration.getResultsTransformOptions().getSupportLevel()).isZero(); + + assertThat(jobConfiguration.getInitInfobaseOptions().getRunMigration()).isFalse(); + assertThat(jobConfiguration.getInitInfobaseOptions().getAdditionalMigrationSteps()).contains("vanessa --settings ./tools/vrunner.first.json"); } } \ No newline at end of file diff --git a/test/unit/resources/jobConfiguration.json b/test/unit/resources/jobConfiguration.json index 2cd66f2..173d261 100644 --- a/test/unit/resources/jobConfiguration.json +++ b/test/unit/resources/jobConfiguration.json @@ -6,6 +6,12 @@ "stages": { "syntaxCheck": true }, + "initInfobase": { + "runMigration": false, + "additionalMigrationSteps": [ + "vanessa --settings ./tools/vrunner.first.json" + ] + }, "syntaxCheck": { "checkModes": ["-ThinClient"] }, diff --git a/vars/initInfobase.groovy b/vars/initInfobase.groovy new file mode 100644 index 0000000..7eabdcb --- /dev/null +++ b/vars/initInfobase.groovy @@ -0,0 +1,10 @@ +import ru.pulsar.jenkins.library.configuration.JobConfiguration +import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.steps.InitInfobase + +def call(JobConfiguration config) { + ContextRegistry.registerDefaultContext(this) + + def initInfobase = new InitInfobase(config) + initInfobase.run() +} \ No newline at end of file diff --git a/vars/pipeline1C.groovy b/vars/pipeline1C.groovy index d07006f..e04064f 100644 --- a/vars/pipeline1C.groovy +++ b/vars/pipeline1C.groovy @@ -46,18 +46,43 @@ void call() { expression { config.stageFlags.needInfobase() } } - steps { - printLocation() + stages { + stage('Создание ИБ') { + steps { + printLocation() - installLocalDependencies() + installLocalDependencies() - dir("build/out") { echo '' } + dir("build/out") { echo '' } - // Создание базы загрузкой конфигурации из хранилища - initFromStorage config + // Создание базы загрузкой конфигурации из хранилища + initFromStorage config + } + } - zipInfobase() + stage('Инициализация ИБ') { + when { + beforeAgent true + expression { config.stageFlags.initSteps } + } + steps { + printLocation() + + // Инициализация и первичная миграция + initInfobase config + } + } + + stage('Архивация ИБ') { + steps { + printLocation() + + zipInfobase() + } + + } } + } stage('Трансформация в формат EDT') {