1
0
mirror of https://github.com/firstBitMarksistskaya/jenkins-lib.git synced 2024-11-27 09:20:51 +02:00

Поддержка загрузки конфигурации из исходников конфигуратора

This commit is contained in:
Nikita Gryzlov 2021-11-01 17:45:57 +03:00
parent b351c5232e
commit f8020afa68
No known key found for this signature in database
GPG Key ID: C3CAA2980494E7E6
14 changed files with 118 additions and 40 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.idea/
.gradle/
build/
bin/
*.iml

View File

@ -3,6 +3,7 @@
"v8version": "8.3",
"srcDir": "src/cf",
"sourceFormat": "designer",
"defaultBranch": "main",
"secrets": {
"storagePath": "UNKNOWN_ID",
"storage": "UNKNOWN_ID"
@ -16,6 +17,7 @@
"smoke": false
},
"initInfobase": {
"initMethod": "fromStorage",
"runMigration": true,
"additionalInitializationSteps": []
},

View File

@ -8,13 +8,17 @@
},
"srcDir" : {
"type" : "string",
"description" : "Путь к корневому каталогу с исходниками конфигурации"
"description" : "Путь к корневому каталогу с исходниками конфигурации, в случае хранения исходников в формате EDT, необходимо указать путь к проекту"
},
"sourceFormat" : {
"type" : "string",
"description" : "Формат исходников конфигурации",
"enum" : [ "edt", "designer" ]
},
"defaultBranch" : {
"type" : "string",
"description" : "Имя ветки по умолчанию"
},
"secrets" : {
"type" : "object",
"id" : "urn:jsonschema:ru:pulsar:jenkins:library:configuration:Secrets",
@ -66,6 +70,11 @@
"id" : "urn:jsonschema:ru:pulsar:jenkins:library:configuration:InitInfobaseOptions",
"description" : "Настройки шага инициализации ИБ",
"properties" : {
"initMethod" : {
"type" : "string",
"description" : "\n Способ инициализации информационной базы.\n Поддерживается три варианта:\n * fromStorage - инициализация информационной базы из хранилища конфигурации;\n * fromSource - инициализация информационной базы из исходников конфигурации;\n * defaultBranchFromStorage - инициализация основной ветки из хранилища конфигурации, остальных - из исходников конфигурации.\n По умолчанию содержит значение \"fromStorage\".",
"enum" : [ "fromStorage", "fromSource", "defaultBranchFromStorage" ]
},
"runMigration" : {
"type" : "boolean",
"description" : "Запустить миграцию ИБ"

View File

@ -3,16 +3,31 @@ package ru.pulsar.jenkins.library.configuration
import com.cloudbees.groovy.cps.NonCPS
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.ObjectMapper
import org.apache.commons.beanutils.BeanUtils
import org.apache.commons.beanutils.BeanUtilsBean
import org.apache.commons.beanutils.ConvertUtilsBean
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.ioc.ContextRegistry
class ConfigurationReader implements Serializable {
private static ObjectMapper mapper
private static BeanUtilsBean beanUtilsBean;
static {
mapper = new ObjectMapper()
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
beanUtilsBean = new BeanUtilsBean(new ConvertUtilsBean() {
@Override
@NonCPS
Object convert(String value, Class clazz) {
if (clazz.isEnum()) {
return Enum.valueOf(clazz, value);
} else {
return super.convert(value, clazz);
}
}
});
}
private static final String DEFAULT_CONFIGURATION_RESOURCE = 'globalConfiguration.json'
@ -57,13 +72,13 @@ class ConfigurationReader implements Serializable {
@NonCPS
private static <T extends Object> void mergeObjects(T baseObject, T objectToMerge, Set<String> nonMergeableSettings) {
BeanUtils.describe(objectToMerge).entrySet().stream()
beanUtilsBean.describe(objectToMerge).entrySet().stream()
.filter({ e -> e.getValue() != null })
.filter({ e -> e.getKey() != "class" })
.filter({ e -> e.getKey() != "metaClass" })
.filter({ e -> !nonMergeableSettings.contains(e.getKey()) })
.forEach { e ->
BeanUtils.setProperty(baseObject, e.getKey(), e.getValue());
beanUtilsBean.setProperty(baseObject, e.getKey(), e.getValue());
}
nonMergeableSettings.forEach({ key ->

View File

@ -0,0 +1,16 @@
package ru.pulsar.jenkins.library.configuration
import com.fasterxml.jackson.annotation.JsonProperty
enum InitInfobaseMethod {
@JsonProperty("fromStorage")
FROM_STORAGE,
@JsonProperty("fromSource")
FROM_SOURCE,
@JsonProperty("defaultBranchFromStorage")
DEFAULT_BRANCH_FROM_STORAGE
}

View File

@ -7,6 +7,15 @@ import com.fasterxml.jackson.annotation.JsonPropertyDescription
@JsonIgnoreProperties(ignoreUnknown = true)
class InitInfobaseOptions implements Serializable {
@JsonPropertyDescription("""
Способ инициализации информационной базы.
Поддерживается три варианта:
* fromStorage - инициализация информационной базы из хранилища конфигурации;
* fromSource - инициализация информационной базы из исходников конфигурации;
* defaultBranchFromStorage - инициализация основной ветки из хранилища конфигурации, остальных - из исходников конфигурации.
По умолчанию содержит значение "fromStorage".""")
InitInfobaseMethod initMethod = InitInfobaseMethod.FROM_STORAGE;
@JsonPropertyDescription("Запустить миграцию ИБ")
boolean runMigration = true
@ -20,7 +29,8 @@ class InitInfobaseOptions implements Serializable {
@NonCPS
String toString() {
return "InitInfobaseOptions{" +
"runMigration=" + runMigration +
"initMethod=" + initMethod +
", runMigration=" + runMigration +
", additionalInitializationSteps=" + additionalInitializationSteps +
'}';
}

View File

@ -1,9 +1,12 @@
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
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.ioc.ContextRegistry
@JsonIgnoreProperties(ignoreUnknown = true)
class JobConfiguration implements Serializable {
@ -20,6 +23,9 @@ class JobConfiguration implements Serializable {
@JsonPropertyDescription("Включение этапов сборок")
StageFlags stageFlags;
@JsonPropertyDescription("Имя ветки по умолчанию. Значение по умолчанию - main.")
String defaultBranch
@JsonPropertyDescription("Идентификаторы сохраненных секретов")
Secrets secrets;
@ -53,7 +59,8 @@ class JobConfiguration implements Serializable {
return "JobConfiguration{" +
"v8version='" + v8version + '\'' +
", srcDir='" + srcDir + '\'' +
", sourceFormat='" + sourceFormat +
", sourceFormat=" + sourceFormat +
", defaultBranch=" + defaultBranch +
", stageFlags=" + stageFlags +
", secrets=" + secrets +
", initInfobaseOptions=" + initInfobaseOptions +
@ -66,6 +73,13 @@ class JobConfiguration implements Serializable {
}
boolean infobaseFromFiles(){
return sourceFormat.EDT
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
def env = steps.env();
String branchName = env.BRANCH_NAME;
def initMethod = initInfobaseOptions.initMethod
return sourceFormat == SourceFormat.EDT ||
(initMethod == InitInfobaseMethod.FROM_SOURCE) ||
(initMethod == InitInfobaseMethod.DEFAULT_BRANCH_FROM_STORAGE && branchName != defaultBranch)
}
}

View File

@ -1,27 +1,12 @@
package ru.pulsar.jenkins.library.configuration
import com.cloudbees.groovy.cps.NonCPS
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
@JsonIgnoreProperties(ignoreUnknown = true)
public enum SourceFormat{
enum SourceFormat {
@JsonProperty("edt")
EDT,
@JsonProperty("designer")
DESIGNER
@Override
@NonCPS
String toString() {
return "SourceFormat{" +
"edt='" + EDT +
"designer='" + DESIGNER +
'}';
}
boolean infobaseFromFiles(){
return EDT
}
}

View File

@ -2,6 +2,7 @@ package ru.pulsar.jenkins.library.steps
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.configuration.SourceFormat
import ru.pulsar.jenkins.library.ioc.ContextRegistry
import ru.pulsar.jenkins.library.utils.Logger
@ -26,25 +27,33 @@ class EdtValidate implements Serializable {
return
}
steps.unstash(DesignerToEdtFormatTransformation.WORKSPACE_ZIP_STASH)
steps.unzip(DesignerToEdtFormatTransformation.WORKSPACE, DesignerToEdtFormatTransformation.WORKSPACE_ZIP)
def env = steps.env();
def resultFile = "$env.WORKSPACE/$RESULT_FILE"
def workspaceLocation = "$env.WORKSPACE/$DesignerToEdtFormatTransformation.WORKSPACE"
String workspaceLocation = "$env.WORKSPACE/$DesignerToEdtFormatTransformation.WORKSPACE"
String projectList;
if (config.sourceFormat == SourceFormat.DESIGNER) {
steps.unstash(DesignerToEdtFormatTransformation.WORKSPACE_ZIP_STASH)
steps.unzip(DesignerToEdtFormatTransformation.WORKSPACE, DesignerToEdtFormatTransformation.WORKSPACE_ZIP)
projectList = "--project-name-list $DesignerToEdtFormatTransformation.PROJECT_NAME"
} else {
projectList = "--project-list '$config.srcDir'"
}
def resultFile = "$env.WORKSPACE/$RESULT_FILE"
steps.createDir(new File(resultFile).getParent())
Logger.println("Выполнение валидации EDT")
def ringCommand = "ring edt workspace validate --workspace-location '$workspaceLocation' --file '$resultFile' --project-name-list $DesignerToEdtFormatTransformation.PROJECT_NAME"
def ringCommand = "ring edt workspace validate --workspace-location '$workspaceLocation' --file '$resultFile' $projectList"
def ringOpts = ['RING_OPTS=-Dfile.encoding=UTF-8 -Dosgi.nl=ru -Duser.language=ru']
steps.withEnv(ringOpts) {
steps.catchError {
steps.cmd(ringCommand)
}
}
steps.archiveArtifacts("$DesignerToEdtFormatTransformation.WORKSPACE/.metadata/.log")
steps.archiveArtifacts(RESULT_FILE)
steps.stash(RESULT_STASH, RESULT_FILE)

View File

@ -2,8 +2,10 @@ package ru.pulsar.jenkins.library.steps
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.configuration.SourceFormat
import ru.pulsar.jenkins.library.ioc.ContextRegistry
import ru.pulsar.jenkins.library.utils.Logger
import ru.pulsar.jenkins.library.utils.VRunner
class InitFromFiles implements Serializable {
@ -23,17 +25,25 @@ class InitFromFiles implements Serializable {
return
}
steps.installLocalDependencies();
Logger.println("Распаковка файлов")
def env = steps.env();
def srcDir = "$env.WORKSPACE/$EdtToDesignerFormatTransformation.CONFIGURATION_DIR"
String srcDir;
steps.unstash(EdtToDesignerFormatTransformation.CONFIGURATION_ZIP_STASH)
steps.unzip(srcDir, EdtToDesignerFormatTransformation.CONFIGURATION_ZIP)
if (config.sourceFormat == SourceFormat.EDT) {
def env = steps.env();
srcDir = "$env.WORKSPACE/$EdtToDesignerFormatTransformation.CONFIGURATION_DIR"
steps.unstash(EdtToDesignerFormatTransformation.CONFIGURATION_ZIP_STASH)
steps.unzip(srcDir, EdtToDesignerFormatTransformation.CONFIGURATION_ZIP)
} else {
srcDir = config.srcDir;
}
Logger.println("Выполнение загрузки конфигурации из файлов")
def initCommand = "oscript_modules/bin/vrunner init-dev --src $srcDir --ibconnection \"/F./build/ib\""
String vrunnerPath = VRunner.getVRunnerPath();
def initCommand = "$vrunnerPath init-dev --src $srcDir --ibconnection \"/F./build/ib\""
steps.cmd(initCommand)
}
}

View File

@ -73,5 +73,6 @@ class jobConfigurationTest {
def run = rule.buildAndAssertSuccess(workflowJob)
rule.assertLogContains("v8version='8.3.12.1500'", run)
rule.assertLogContains("sonarScannerToolName='sonar-scanner'", run)
rule.assertLogContains("initMethod=FROM_SOURCE", run)
}
}

View File

@ -1,3 +1,6 @@
{
"v8version": "8.3.12.1500"
"v8version": "8.3.12.1500",
"initInfobase": {
"initMethod": "fromSource"
}
}

View File

@ -4,6 +4,10 @@ import ru.pulsar.jenkins.library.utils.VersionParser
def call(JobConfiguration jobConfiguration) {
printLocation()
installLocalDependencies();
def storageVersion = VersionParser.storage()
def storageVersionParameter = storageVersion == "" ? "" : "--storage-ver $storageVersion"

View File

@ -1,6 +1,7 @@
/* groovylint-disable NestedBlockDepth */
import groovy.transform.Field
import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.configuration.SourceFormat
import java.util.concurrent.TimeUnit
@ -55,7 +56,7 @@ void call() {
}
when {
beforeAgent true
expression { config.infobaseFromFiles() }
expression { config.stageFlags.needInfobase() && config.sourceFormat == SourceFormat.EDT }
}
steps {
edtToDesignerFormatTransformation config
@ -66,8 +67,6 @@ void call() {
steps {
printLocation()
installLocalDependencies()
createDir('build/out')
script {
@ -115,7 +114,7 @@ void call() {
expression { config.sourceFormat.DESIGNER && config.stageFlags.edtValidate}
}
steps {
edtTransform config
designerToEdtFormatTransformation config
}
}
}