diff --git a/src/ru/pulsar/jenkins/library/IStepExecutor.groovy b/src/ru/pulsar/jenkins/library/IStepExecutor.groovy index cff3f66..4eac192 100644 --- a/src/ru/pulsar/jenkins/library/IStepExecutor.groovy +++ b/src/ru/pulsar/jenkins/library/IStepExecutor.groovy @@ -35,4 +35,10 @@ interface IStepExecutor { def stash(String name, String includes) def unstash(String name) + + def zip(String dir, String zipFile) + + def zip(String dir, String zipFile, String glob) + + def unzip(String dir, String zipFile) } \ No newline at end of file diff --git a/src/ru/pulsar/jenkins/library/StepExecutor.groovy b/src/ru/pulsar/jenkins/library/StepExecutor.groovy index 7c8f06b..e78ad47 100644 --- a/src/ru/pulsar/jenkins/library/StepExecutor.groovy +++ b/src/ru/pulsar/jenkins/library/StepExecutor.groovy @@ -88,4 +88,14 @@ class StepExecutor implements IStepExecutor { def unstash(String name) { steps.unstash name } + + @Override + def zip(String dir, String zipFile, String glob = '') { + steps.zip dir: dir, zipFile: zipFile, glob: glob + } + + @Override + def unzip(String dir, String zipFile) { + steps.unzip dir: dir, zipFile: zipFile + } } diff --git a/src/ru/pulsar/jenkins/library/steps/EdtTransform.groovy b/src/ru/pulsar/jenkins/library/steps/EdtTransform.groovy new file mode 100644 index 0000000..a13fdb7 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/steps/EdtTransform.groovy @@ -0,0 +1,52 @@ +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 EdtTransform implements Serializable { + + public static final String PROJECT_NAME = 'temp' + public static final String WORKSPACE = 'build/edt-workspace' + public static final String WORKSPACE_ZIP = 'build/edt-workspace.zip' + public static final String WORKSPACE_ZIP_STASH = 'edt-workspace-zip' + + private final JobConfiguration config; + private final String rootDir + + EdtTransform(JobConfiguration config, String rootDir = 'src/cf') { + this.config = config + this.rootDir = rootDir + } + + def run() { + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + Logger.printLocation() + + if (!config.stageFlags.edtValidate) { + Logger.println("EDT validate step is disabled. No transform is needed.") + return + } + + def env = steps.env(); + + def workspaceDir = "$env.WORKSPACE/$WORKSPACE" + def configurationRoot = new File(env.WORKSPACE, rootDir).getAbsolutePath() + + steps.createDir(workspaceDir) + + Logger.println("Конвертация исходников из формата конфигуратора в формат EDT") + + def ringCommand = "ring edt workspace import --configuration-files '$configurationRoot' --project-name $PROJECT_NAME --workspace-location '$workspaceDir'" + + def ringOpts = ['RING_OPTS=-Dfile.encoding=UTF-8 -Dosgi.nl=ru -Duser.language=ru'] + steps.withEnv(ringOpts) { + steps.cmd(ringCommand) + } + + steps.zip(WORKSPACE, WORKSPACE_ZIP) + steps.stash(WORKSPACE_ZIP_STASH, WORKSPACE_ZIP) + } +} diff --git a/src/ru/pulsar/jenkins/library/steps/EdtValidate.groovy b/src/ru/pulsar/jenkins/library/steps/EdtValidate.groovy index c295e30..6d91c15 100644 --- a/src/ru/pulsar/jenkins/library/steps/EdtValidate.groovy +++ b/src/ru/pulsar/jenkins/library/steps/EdtValidate.groovy @@ -7,6 +7,9 @@ import ru.pulsar.jenkins.library.utils.Logger class EdtValidate implements Serializable { + public static final String RESULT_STASH = 'edt-validate' + public static final String RESULT_FILE = 'build/out/edt-validate.out' + private final JobConfiguration config; private final String rootDir @@ -25,35 +28,25 @@ class EdtValidate implements Serializable { return } + steps.unstash(EdtTransform.WORKSPACE_ZIP_STASH) + steps.unzip(EdtTransform.WORKSPACE_ZIP, EdtTransform.WORKSPACE) + def env = steps.env(); - def resultFileRelative = 'build/out/edt-validate.out' - def projectName = 'temp' - def workspaceDir = "$env.WORKSPACE/build/workspace" - def resultFile = "$env.WORKSPACE/$resultFileRelative" - def configurationRoot = new File(env.WORKSPACE, rootDir).getAbsolutePath() + def resultFile = "$env.WORKSPACE/$RESULT_FILE" - steps.createDir(workspaceDir) steps.createDir(new File(resultFile).getParent()) - Logger.println("Конвертация исходников из формата конфигуратора в формат EDT") - - def ringCommand = "ring edt workspace import --configuration-files '$configurationRoot' --project-name $projectName --workspace-location '$workspaceDir'" - - def ringOpts = ['_JAVA_OPTS="-Dfile.encoding=UTF-8 -Dosgi.nl=ru -Duser.language=ru"'] - steps.withEnv(ringOpts) { - steps.cmd(ringCommand) - } - Logger.println("Выполнение валидации EDT") - ringCommand = "ring edt workspace validate --workspace-location '$workspaceDir' --file '$resultFile' --project-name-list $projectName" + def ringCommand = "ring edt workspace validate --workspace-location '$EdtTransform.WORKSPACE' --file '$resultFile' --project-name-list $EdtTransform.PROJECT_NAME" + def ringOpts = ['RING_OPTIONS=-Dfile.encoding=UTF-8 -Dosgi.nl=ru -Duser.language=ru'] steps.withEnv(ringOpts) { steps.cmd(ringCommand) } - steps.archiveArtifacts(resultFileRelative) - steps.stash('edt-validate', resultFileRelative) + steps.archiveArtifacts(RESULT_FILE) + steps.stash(RESULT_STASH, RESULT_FILE) } } diff --git a/src/ru/pulsar/jenkins/library/steps/ResultsTransformer.groovy b/src/ru/pulsar/jenkins/library/steps/ResultsTransformer.groovy index 79cdd30..a0e3f04 100644 --- a/src/ru/pulsar/jenkins/library/steps/ResultsTransformer.groovy +++ b/src/ru/pulsar/jenkins/library/steps/ResultsTransformer.groovy @@ -7,12 +7,13 @@ import ru.pulsar.jenkins.library.utils.Logger class ResultsTransformer implements Serializable { - private final JobConfiguration config; - private final String rootDir + public static final String RESULT_STASH = 'edt-generic-issue' + public static final String RESULT_FILE = 'build/out/edt-generic-issue.json' - ResultsTransformer(JobConfiguration config, String rootDir = 'src/cf') { + private final JobConfiguration config; + + ResultsTransformer(JobConfiguration config) { this.config = config - this.rootDir = rootDir } def run() { @@ -32,17 +33,19 @@ class ResultsTransformer implements Serializable { return } - steps.unstash('edt-validate') + steps.unstash(EdtTransform.WORKSPACE_ZIP_STASH) + steps.unzip(EdtTransform.WORKSPACE_ZIP, EdtTransform.WORKSPACE) + + steps.unstash(EdtValidate.RESULT_STASH) Logger.println("Конвертация результата EDT в Generic Issue") - def genericIssueRelative = "build/out/edt-generic-issue.json" - def edtValidateFile = "$env.WORKSPACE/build/out/edt-validate.out" - def genericIssueFile = "$env.WORKSPACE/$genericIssueRelative" + def edtValidateFile = "$env.WORKSPACE/$EdtValidate.RESULT_FILE" + def genericIssueFile = "$env.WORKSPACE/$RESULT_FILE" - steps.cmd("stebi convert $edtValidateFile $genericIssueFile $rootDir") + steps.cmd("stebi convert $edtValidateFile $genericIssueFile $EdtTransform.WORKSPACE") - steps.archiveArtifacts(genericIssueRelative) - steps.stash('edt-generic-issue', genericIssueRelative) + steps.archiveArtifacts(RESULT_FILE) + steps.stash(RESULT_STASH, RESULT_FILE) } } diff --git a/vars/edtTransform.groovy b/vars/edtTransform.groovy new file mode 100644 index 0000000..ce1b8f5 --- /dev/null +++ b/vars/edtTransform.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.EdtTransform + +def call(JobConfiguration config, String rootDir = 'src/cf') { + ContextRegistry.registerDefaultContext(this) + + def edtTransform = new EdtTransform(config, rootDir) + edtTransform.run() +} diff --git a/vars/pipeline1C.groovy b/vars/pipeline1C.groovy index df6cdfd..f5d69b6 100644 --- a/vars/pipeline1C.groovy +++ b/vars/pipeline1C.groovy @@ -35,13 +35,13 @@ void call() { } } - stage('1C') { - agent { - label agent1C - } + stage('Подготовка') { + parallel { + stage('Подготовка 1C базы') { + agent { + label agent1C + } - stages { - stage('Подготовка базы') { steps { printLocation() @@ -56,42 +56,57 @@ void call() { } } - stage('Проверка качества') { - parallel { - stage('EDT контроль') { - agent { - label 'edt' - } - steps { - edtValidate config - } - } - - stage('Синтаксический контроль') { - steps { - syntaxCheck config - } - } - - stage('Дымовые тесты') { - steps { - smoke config - } - } - } - } - - stage('Трансформация результатов') { + stage('Трансформация в формат EDT') { agent { - label 'oscript' + label 'edt' } steps { - transform config + edtTransform config } } } } + stage('Проверка качества') { + parallel { + stage('EDT контроль') { + agent { + label 'edt' + } + steps { + edtValidate config + } + } + + stage('Синтаксический контроль') { + agent { + label agent1C + } + steps { + syntaxCheck config + } + } + + stage('Дымовые тесты') { + agent { + label agent1C + } + steps { + smoke config + } + } + } + } + + stage('Трансформация результатов') { + agent { + label 'oscript' + } + steps { + transform config + } + } + stage('SonarQube') { agent { label 'sonar'