diff --git a/src/ru/pulsar/jenkins/library/IStepExecutor.groovy b/src/ru/pulsar/jenkins/library/IStepExecutor.groovy index c2bb441..53af9f4 100644 --- a/src/ru/pulsar/jenkins/library/IStepExecutor.groovy +++ b/src/ru/pulsar/jenkins/library/IStepExecutor.groovy @@ -1,5 +1,6 @@ package ru.pulsar.jenkins.library +import org.jenkinsci.plugins.credentialsbinding.MultiBinding import org.jenkinsci.plugins.pipeline.utility.steps.fs.FileWrapper import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction @@ -29,6 +30,8 @@ interface IStepExecutor { void tool(String toolName) + def withCredentials(List bindings, Closure body) + void withSonarQubeEnv(String installationName, Closure body) EnvironmentAction env() diff --git a/src/ru/pulsar/jenkins/library/StepExecutor.groovy b/src/ru/pulsar/jenkins/library/StepExecutor.groovy index 602d662..f61b12b 100644 --- a/src/ru/pulsar/jenkins/library/StepExecutor.groovy +++ b/src/ru/pulsar/jenkins/library/StepExecutor.groovy @@ -1,5 +1,6 @@ package ru.pulsar.jenkins.library +import org.jenkinsci.plugins.credentialsbinding.MultiBinding import org.jenkinsci.plugins.pipeline.utility.steps.fs.FileWrapper import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction import ru.yandex.qatools.allure.jenkins.config.ResultsConfig @@ -69,6 +70,13 @@ class StepExecutor implements IStepExecutor { } } + @Override + def withCredentials(List bindings, Closure body) { + steps.withCredentials(bindings) { + body() + } + } + @Override EnvironmentAction env() { return steps.env diff --git a/src/ru/pulsar/jenkins/library/steps/InitFromStorage.groovy b/src/ru/pulsar/jenkins/library/steps/InitFromStorage.groovy new file mode 100644 index 0000000..48537d1 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/steps/InitFromStorage.groovy @@ -0,0 +1,50 @@ +package ru.pulsar.jenkins.library.steps + +import org.jenkinsci.plugins.credentialsbinding.impl.StringBinding +import org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding +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 +import ru.pulsar.jenkins.library.utils.VRunner +import ru.pulsar.jenkins.library.utils.VersionParser + +class InitFromStorage implements Serializable { + + private final JobConfiguration config; + + InitFromStorage(JobConfiguration config) { + this.config = config + } + + def run() { + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + Logger.printLocation() + + if (config.infobaseFromFiles()) { + Logger.println("init infoBase from storage is disabled") + return + } + + steps.installLocalDependencies(); + + def storageVersion = VersionParser.storage() + def storageVersionParameter = storageVersion == "" ? "" : "--storage-ver $storageVersion" + + steps.withCredentials(Arrays.asList( + new UsernamePasswordMultiBinding( + 'STORAGE_USR', + 'STORAGE_PSW', + config.secrets.storage + ), + new StringBinding( + 'STORAGE_PATH', + config.secrets.storagePath + ) + )) { + String vrunnerPath = VRunner.getVRunnerPath(); + steps.cmd "$vrunnerPath init-dev --storage --storage-name $STORAGE_PATH --storage-user $STORAGE_USR --storage-pwd $STORAGE_PSW $storageVersionParameter --ibconnection \"/F./build/ib\"" + } + } +} diff --git a/vars/initFromStorage.groovy b/vars/initFromStorage.groovy index fb8cd69..3349381 100644 --- a/vars/initFromStorage.groovy +++ b/vars/initFromStorage.groovy @@ -1,28 +1,10 @@ import ru.pulsar.jenkins.library.configuration.JobConfiguration -import ru.pulsar.jenkins.library.utils.VRunner -import ru.pulsar.jenkins.library.utils.VersionParser +import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.steps.InitFromStorage -def call(JobConfiguration jobConfiguration) { +def call(JobConfiguration config) { + ContextRegistry.registerDefaultContext(this) - printLocation() - - installLocalDependencies(); - - def storageVersion = VersionParser.storage() - def storageVersionParameter = storageVersion == "" ? "" : "--storage-ver $storageVersion" - - withCredentials([ - usernamePassword( - credentialsId: jobConfiguration.secrets.storage, - passwordVariable: 'STORAGE_PSW', - usernameVariable: 'STORAGE_USR' - ), - string( - credentialsId: jobConfiguration.secrets.storagePath, - variable: 'STORAGE_PATH' - ) - ]) { - String vrunnerPath = VRunner.getVRunnerPath(); - cmd "$vrunnerPath init-dev --storage --storage-name $STORAGE_PATH --storage-user $STORAGE_USR --storage-pwd $STORAGE_PSW $storageVersionParameter --ibconnection \"/F./build/ib\"" - } + def initFromStorage = new InitFromStorage(config) + initFromStorage.run() } \ No newline at end of file