Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Сохранение ИБ в виде артефакта после выполнения всех шагов инциализации #149

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
14 changes: 13 additions & 1 deletion resources/globalConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,32 @@
"additionalInitializationSteps": [],
"templateDBPath": "",
"vrunnerSettings": "./tools/vrunner.json",
"archiveInfobase": {
"onAlways": false,
"onFailure": true,
"onUnstable": false,
"onSuccess": false
},
"extensions": []
},
"bdd": {
"vrunnerSteps": [
"vanessa --settings ./tools/vrunner.json"
],
"archiveInfobase": {
"onAlways": false,
"onFailure": true,
"onUnstable": false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут возможно имеет смысл выставить в true, т.к. при падении тестов стейдж помечается как UNSTABLE, а не FAILED. ну или по крайней мере расписать это в документации.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

согласен, выставил true тут и в initInfobase

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я вот думаю, мы мастер не положим такими приколами, кстати? :)
может вырубить все по дефолту?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вырубил

<поднятьворотачутьчуть.jpg>

"onSuccess": false
},
"coverage": false,
"dbgsPort": 1550
},
"sonarqube": {
"sonarQubeInstallation": "",
"useSonarScannerFromPath": true,
"sonarScannerToolName": "sonar-scanner",
"infoBaseUpdateModuleName" : "",
"infoBaseUpdateModuleName": "",
"branchAnalysisConfiguration": "fromEnv",
"waitForQualityGate": false
},
Expand Down
51 changes: 43 additions & 8 deletions resources/schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
{
"$schema" : "http://json-schema.org/draft-07/schema#",
"definitions" : {
"ArchiveInfobaseOptions" : {
"type" : "object",
"properties" : {
"onAlways" : {
"type" : "boolean",
"description" : "Сохранять всегда"
},
"onFailure" : {
"type" : "boolean",
"description" : "Сохранять при падении сборки"
},
"onSuccess" : {
"type" : "boolean",
"description" : "Сохранять при успешной сборке"
},
"onUnstable" : {
"type" : "boolean",
"description" : "Сохранять при нестабильной сборке"
}
}
},
"EmailExtConfiguration" : {
"type" : "object",
"properties" : {
Expand Down Expand Up @@ -28,15 +49,22 @@
"bdd" : {
"type" : "object",
"properties" : {
"archiveInfobase" : {
"allOf" : [ {
"$ref" : "#/definitions/ArchiveInfobaseOptions"
}, {
"description" : "Настройки сохранения базы после выполнения всех шагов\n "
} ]
},
"coverage" : {
"type" : "boolean",
"description" : "Выполнять замер покрытия",
"default" : false
"default" : "false"
},
"dbgsPort" : {
"type" : "integer",
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия",
"default" : 1550
"default" : "1550"
},
"vrunnerSteps" : {
"description" : "Шаги, запускаемые через vrunner.\n В каждой строке передается отдельная команда \n vrunner и ее аргументы (например, \"vanessa --settings ./tools/vrunner.json\").\n По умолчанию содержит одну команду \"vanessa --settings ./tools/vrunner.json\".\n ",
Expand Down Expand Up @@ -80,6 +108,13 @@
"type" : "string"
}
},
"archiveInfobase" : {
"allOf" : [ {
"$ref" : "#/definitions/ArchiveInfobaseOptions"
}, {
"description" : "Настройки сохранения базы после выполнения всех шагов\n "
} ]
},
"extensions" : {
"description" : "Массив расширений для загрузки в конфигурацию.",
"type" : "array",
Expand Down Expand Up @@ -250,12 +285,12 @@
"coverage" : {
"type" : "boolean",
"description" : "Выполнять замер покрытия",
"default" : false
"default" : "false"
},
"dbgsPort" : {
"type" : "integer",
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия",
"default" : 1550
"default" : "1550"
},
"publishToAllureReport" : {
"type" : "boolean",
Expand Down Expand Up @@ -381,12 +416,12 @@
"publishToAllureReport" : {
"type" : "boolean",
"description" : "Выполнять публикацию результатов в отчет Allure.\n По умолчанию выключено.\n ",
"default": false
"default" : "false"
},
"publishToJUnitReport" : {
"type" : "boolean",
"description" : "Выполнять публикацию результатов в отчет JUnit.\n По умолчанию включено.\n ",
"default": true
"default" : "true"
},
"vrunnerSettings" : {
"type" : "string",
Expand Down Expand Up @@ -475,12 +510,12 @@
"coverage" : {
"type" : "boolean",
"description" : "Выполнять замер покрытия",
"default" : false
"default" : "false"
},
"dbgsPort" : {
"type" : "integer",
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия",
"default" : 1550
"default" : "1550"
},
"publishToAllureReport" : {
"type" : "boolean",
Expand Down
3 changes: 2 additions & 1 deletion src/JobConfigurationSchemaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static void main(String[] args) {
writer.write(jsonSchema.toPrettyString());
System.out.println(jsonSchema.toPrettyString());
} catch (IOException e) {
e.printStackTrace();
//noinspection CallToPrintStackTrace
e.printStackTrace();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/ru/pulsar/jenkins/library/IStepExecutor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ interface IStepExecutor {
@SuppressWarnings('unused')
def zip(String dir, String zipFile, String glob)

def zip(String dir, String zipFile, String glob, boolean archive)

def unzip(String dir, String zipFile)

@SuppressWarnings('unused')
Expand Down
5 changes: 5 additions & 0 deletions src/ru/pulsar/jenkins/library/StepExecutor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ class StepExecutor implements IStepExecutor {
steps.zip dir: dir, zipFile: zipFile, glob: glob, overwrite: true
}

@Override
def zip(String dir, String zipFile, String glob = '', boolean archive) {
steps.zip dir: dir, zipFile: zipFile, glob: glob, overwrite: true, archive: archive
}

@Override
def unzip(String dir, String zipFile, quiet = true) {
steps.unzip dir: dir, zipFile: zipFile, quiet: quiet
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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 ArchiveInfobaseOptions implements Serializable {

@JsonPropertyDescription("Сохранять всегда")
Boolean onAlways = false
@JsonPropertyDescription("Сохранять при успешной сборке")
Boolean onSuccess = false
@JsonPropertyDescription("Сохранять при падении сборки")
Boolean onFailure = false
@JsonPropertyDescription("Сохранять при нестабильной сборке")
Boolean onUnstable = false

@Override
@NonCPS
String toString() {
return "ArchiveInfobaseOptions{" +
"onAlways=" + onAlways +
", onSuccess=" + onSuccess +
", onFailure=" + onFailure +
", onUnstable=" + onUnstable +
'}';
}
}


5 changes: 5 additions & 0 deletions src/ru/pulsar/jenkins/library/configuration/BddOptions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ class BddOptions extends StepCoverageOptions implements Serializable {
'vanessa --settings ./tools/vrunner.json'
]

@JsonPropertyDescription("""Настройки сохранения базы после выполнения всех шагов
""")
ArchiveInfobaseOptions archiveInfobase

@Override
@NonCPS
String toString() {
return "BddOptions{" +
"vrunnerSteps=" + vrunnerSteps +
"archiveInfobase=" + archiveInfobase +
ovcharenko-di marked this conversation as resolved.
Show resolved Hide resolved
"coverage=" + coverage +
"dbgsPort=" + dbgsPort +
'}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ConfigurationReader implements Serializable {
"yaxunitOptions",
"syntaxCheckOptions",
"resultsTransformOptions",
"archiveInfobase",
"notificationsOptions",
"emailNotificationOptions",
"alwaysEmailOptions",
Expand All @@ -83,6 +84,7 @@ class ConfigurationReader implements Serializable {
mergeInitInfoBaseOptions(baseConfiguration.initInfoBaseOptions, configurationToMerge.initInfoBaseOptions)
mergeBddOptions(baseConfiguration.bddOptions, configurationToMerge.bddOptions)
mergeSyntaxCheckOptions(baseConfiguration.syntaxCheckOptions, configurationToMerge.syntaxCheckOptions)
// mergeArchiveInfobaseOptions(baseConfiguration.archiveInfobaseOptions, configurationToMerge.archiveInfobaseOptions)
ovcharenko-di marked this conversation as resolved.
Show resolved Hide resolved
mergeNotificationsOptions(baseConfiguration.notificationsOptions, configurationToMerge.notificationsOptions)

return baseConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class InitInfoBaseOptions implements Serializable {
""")
String templateDBPath

@JsonPropertyDescription("""Настройки сохранения базы после выполнения всех шагов
""")
ArchiveInfobaseOptions archiveInfobase

@JsonPropertyDescription("Массив расширений для загрузки в конфигурацию.")
Extension[] extensions

Expand Down Expand Up @@ -80,6 +84,7 @@ class InitInfoBaseOptions implements Serializable {
", vrunnerSettings=" + vrunnerSettings +
", templateDBPath=" + templateDBPath +
", additionalInitializationSteps=" + additionalInitializationSteps +
", archiveInfobase=" + archiveInfobase +
", extensions=" + extensions +
'}'
}
Expand Down
2 changes: 1 addition & 1 deletion src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Yaxunit implements Serializable, Coverable {
}

if (options.publishToAllureReport) {
String allureReport = "./build/out/allure/yaxunit/junit.xml"
String allureReport = "./build/out/allure/yaxunit/allure.xml"
FilePath pathToAllureReport = FileUtils.getFilePath("$env.WORKSPACE/$allureReport")
String allureReportDir = FileUtils.getLocalPath(pathToAllureReport.getParent())

Expand Down
64 changes: 64 additions & 0 deletions src/ru/pulsar/jenkins/library/steps/ZipInfobase.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ru.pulsar.jenkins.library.steps

import hudson.model.Result
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.configuration.ArchiveInfobaseOptions
import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.ioc.ContextRegistry
import ru.pulsar.jenkins.library.utils.Logger

class ZipInfobase implements Serializable {

private final JobConfiguration config
private final String stage

ZipInfobase(JobConfiguration config, String stage) {
this.config = config
this.stage = stage
}

def run() {
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()

Logger.printLocation()

def currentBuild = steps.currentBuild()
def currentResult = Result.fromString(currentBuild.getCurrentResult())

def archiveInfobaseOptions = getArchiveInfobaseOptionsForStage(config, stage)

def archiveName
if (stage == 'initInfoBase') {
archiveName = "1Cv8.1CD.zip"
} else {
archiveName = "1Cv8.1CD.${stage}.zip"
}

// опция отвечает только за то, будет ли файл сохранен в виде артефакта
def archiveInfobase = false
if (archiveInfobaseOptions.onAlways
|| (archiveInfobaseOptions.onFailure && (currentResult == Result.FAILURE || currentResult == Result.ABORTED))
|| (archiveInfobaseOptions.onUnstable && currentResult == Result.UNSTABLE)
|| (archiveInfobaseOptions.onSuccess && currentResult == Result.SUCCESS)) {
archiveInfobase = true
}

steps.zip('build/ib', archiveName, '1Cv8.1CD', archiveInfobase)
steps.stash(archiveName, archiveName, false)
}

private static ArchiveInfobaseOptions getArchiveInfobaseOptionsForStage(JobConfiguration config, String stageName) {

def defaultOptions = new ArchiveInfobaseOptions()
if (!stageName) {
return defaultOptions
}

try {
return config."${stageName}Options".archiveInfobase
} catch(Exception e) {
Logger.println(e.message)
return defaultOptions
}
ovcharenko-di marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import ru.pulsar.jenkins.library.configuration.sonarqube.GenericIssueFormat;
import ru.pulsar.jenkins.library.utils.TestUtils;
Expand Down Expand Up @@ -66,6 +65,7 @@ void testCreateJobConfigurationObject() throws IOException {
assertThat(jobConfiguration.getYaxunitOptions().getDbgsPort()).isEqualTo(1550);

assertThat(jobConfiguration.getInitInfoBaseOptions().getRunMigration()).isFalse();
assertThat(jobConfiguration.getInitInfoBaseOptions().getArchiveInfobase().getOnAlways()).isTrue();
assertThat(jobConfiguration.getInitInfoBaseOptions().getAdditionalInitializationSteps()).contains("vanessa --settings ./tools/vrunner.first.json");

assertThat(jobConfiguration.getBddOptions().getVrunnerSteps()).contains("vanessa --settings ./tools/vrunner.json");
Expand Down
5 changes: 4 additions & 1 deletion test/unit/resources/jobConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
"initInfoBase"
]
}
]
],
"archiveInfobase": {
"onAlways": true
}
},
"sonarqube": {
"sonarQubeInstallation": "qa",
Expand Down
12 changes: 11 additions & 1 deletion vars/pipeline1C.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void call() {
timeout(time: config.timeoutOptions.zipInfoBase, unit: TimeUnit.MINUTES) {
printLocation()

zipInfobase()
zipInfobase config, 'initInfoBase'
}
}
}
Expand Down Expand Up @@ -237,6 +237,16 @@ void call() {
}
}
}

stage('Архивация ИБ') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет ли смысла сразу везде сделать?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

думал об этом, но лично у меня дымовые и юниты выполняются в транзакции, поэтому сохранять ИБ после этих этапов нет смысла

я посчитал, что у большинства пользователей библиотеки ситуация аналогичная (могу ошибаться)

steps {
timeout(time: config.timeoutOptions.zipInfoBase, unit: TimeUnit.MINUTES) {
printLocation()

zipInfobase config, 'bdd'
}
}
}
}
}

Expand Down
Loading
Loading