From 01ce79724522e8e3bb154df3e5a46be4c2c7f0a7 Mon Sep 17 00:00:00 2001 From: Roland Stengel Date: Thu, 25 Jul 2019 11:57:21 +0200 Subject: [PATCH 1/2] harmonize docker configuration properties support the configuration of the docker arguments dockerEnvVars dockerOptions dockerWorkspace for all steps. --- test/groovy/BatsExecuteTestsTest.groovy | 26 ++++++++++ test/groovy/GaugeExecuteTestsTest.groovy | 28 +++++++++++ test/groovy/KarmaExecuteTestsTest.groovy | 26 ++++++++++ test/groovy/MtaBuildTest.groovy | 23 +++++++++ test/groovy/NewmanExecuteTest.groovy | 26 ++++++++++ test/groovy/NpmExecuteTest.groovy | 26 ++++++++++ test/groovy/SeleniumExecuteTestsTest.groovy | 27 +++++++++++ test/groovy/SnykExecuteTest.groovy | 31 ++++++++++++ test/groovy/WhitesourceExecuteScanTest.groovy | 48 +++++++++++++++++++ vars/batsExecuteTests.groovy | 13 ++++- vars/gaugeExecuteTests.groovy | 7 ++- vars/karmaExecuteTests.groovy | 3 ++ vars/mtaBuild.groovy | 16 +++++-- vars/newmanExecute.groovy | 9 ++++ vars/npmExecute.groovy | 13 ++++- vars/seleniumExecuteTests.groovy | 3 ++ vars/snykExecute.groovy | 13 ++++- vars/whitesourceExecuteScan.groovy | 15 +++++- 18 files changed, 344 insertions(+), 9 deletions(-) diff --git a/test/groovy/BatsExecuteTestsTest.groovy b/test/groovy/BatsExecuteTestsTest.groovy index ab284cdb2..66adf427c 100644 --- a/test/groovy/BatsExecuteTestsTest.groovy +++ b/test/groovy/BatsExecuteTestsTest.groovy @@ -70,6 +70,32 @@ class BatsExecuteTestsTest extends BasePiperTest { assertJobStatusSuccess() } + @Test + void testDockerFromCustomStepConfiguration() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '/path/to/workspace' + + nullScript.commonPipelineEnvironment.configuration = [steps:[batsExecuteTests:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]] + + stepRule.step.batsExecuteTests( + script: nullScript, + juStabUtils: utils + ) + + assert expectedImage == dockerExecuteRule.dockerParams.dockerImage + assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions + assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars) + assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace + } + @Test void testTap() { stepRule.step.batsExecuteTests( diff --git a/test/groovy/GaugeExecuteTestsTest.groovy b/test/groovy/GaugeExecuteTestsTest.groovy index 2c61e0855..f0883e5f0 100644 --- a/test/groovy/GaugeExecuteTestsTest.groovy +++ b/test/groovy/GaugeExecuteTestsTest.groovy @@ -12,6 +12,7 @@ class GaugeExecuteTestsTest extends BasePiperTest { private JenkinsStepRule stepRule = new JenkinsStepRule(this) private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this) + private JenkinsDockerExecuteRule dockerExecuteRule = new JenkinsDockerExecuteRule(this) private JenkinsEnvironmentRule environmentRule = new JenkinsEnvironmentRule(this) private ExpectedException thrown = ExpectedException.none() @@ -21,6 +22,7 @@ class GaugeExecuteTestsTest extends BasePiperTest { .around(new JenkinsReadYamlRule(this)) .around(shellRule) .around(loggingRule) + .around(dockerExecuteRule) .around(environmentRule) .around(stepRule) .around(thrown) @@ -67,6 +69,32 @@ class GaugeExecuteTestsTest extends BasePiperTest { assertJobStatusSuccess() } + @Test + void testDockerFromCustomStepConfiguration() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['HUB':'', 'HUB_URL':'', 'env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '/path/to/workspace' + + nullScript.commonPipelineEnvironment.configuration = [steps:[gaugeExecuteTests:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]] + + stepRule.step.gaugeExecuteTests( + script: nullScript, + juStabUtils: utils + ) + + assert expectedImage == seleniumParams.dockerImage + assert expectedOptions == seleniumParams.dockerOptions + assert expectedEnvVars.equals(seleniumParams.dockerEnvVars) + assert expectedWorkspace == seleniumParams.dockerWorkspace + } + @Test void testExecuteGaugeNode() throws Exception { stepRule.step.gaugeExecuteTests( diff --git a/test/groovy/KarmaExecuteTestsTest.groovy b/test/groovy/KarmaExecuteTestsTest.groovy index c40af9a32..69293773d 100644 --- a/test/groovy/KarmaExecuteTestsTest.groovy +++ b/test/groovy/KarmaExecuteTestsTest.groovy @@ -53,6 +53,32 @@ class KarmaExecuteTestsTest extends BasePiperTest { assertJobStatusSuccess() } + @Test + void testDockerFromCustomStepConfiguration() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['NO_PROXY':'', 'no_proxy':'', 'env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '/path/to/workspace' + + nullScript.commonPipelineEnvironment.configuration = [steps:[karmaExecuteTests:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]] + + stepRule.step.karmaExecuteTests( + script: nullScript, + juStabUtils: utils + ) + + assert expectedImage == seleniumParams.dockerImage + assert expectedOptions == seleniumParams.dockerOptions + assert expectedEnvVars.equals(seleniumParams.dockerEnvVars) + assert expectedWorkspace == seleniumParams.dockerWorkspace + } + @Test void testMultiModules() throws Exception { stepRule.step.karmaExecuteTests( diff --git a/test/groovy/MtaBuildTest.groovy b/test/groovy/MtaBuildTest.groovy index 0cc67ea91..4d6194409 100644 --- a/test/groovy/MtaBuildTest.groovy +++ b/test/groovy/MtaBuildTest.groovy @@ -169,6 +169,29 @@ public class MtaBuildTest extends BasePiperTest { assert shellRule.shell.find(){ c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')} } + @Test + void dockerFromCustomStepConfigurationTest() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '-w /path/to/workspace' + + nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]] + + stepRule.step.mtaBuild(script: nullScript) + + assert expectedImage == dockerExecuteRule.dockerParams.dockerImage + assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions + assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars) + assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace + } + @Test void canConfigureDockerImage() { diff --git a/test/groovy/NewmanExecuteTest.groovy b/test/groovy/NewmanExecuteTest.groovy index 5e3d82a16..f8be4f859 100644 --- a/test/groovy/NewmanExecuteTest.groovy +++ b/test/groovy/NewmanExecuteTest.groovy @@ -77,6 +77,32 @@ class NewmanExecuteTest extends BasePiperTest { assertJobStatusSuccess() } + @Test + void testDockerFromCustomStepConfiguration() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '/path/to/workspace' + + nullScript.commonPipelineEnvironment.configuration = [steps:[newmanExecute:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]] + + stepRule.step.newmanExecute( + script: nullScript, + juStabUtils: utils + ) + + assert expectedImage == dockerExecuteRule.dockerParams.dockerImage + assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions + assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars) + assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace + } + @Test void testGlobalInstall() throws Exception { stepRule.step.newmanExecute( diff --git a/test/groovy/NpmExecuteTest.groovy b/test/groovy/NpmExecuteTest.groovy index 610f23ad3..eebcaea2f 100644 --- a/test/groovy/NpmExecuteTest.groovy +++ b/test/groovy/NpmExecuteTest.groovy @@ -40,6 +40,32 @@ class NpmExecuteTest extends BasePiperTest { assertEquals 'node:8-stretch', dockerExecuteRule.dockerParams.dockerImage } + @Test + void testDockerFromCustomStepConfiguration() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '/path/to/workspace' + + nullScript.commonPipelineEnvironment.configuration = [steps:[npmExecute:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]] + + stepRule.step.npmExecute( + script: nullScript, + juStabUtils: utils + ) + + assert expectedImage == dockerExecuteRule.dockerParams.dockerImage + assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions + assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars) + assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace + } + @Test void testNpmExecuteWithClosure() { stepRule.step.npmExecute(script: nullScript, dockerImage: 'node:8-stretch', npmCommand: 'run build') { } diff --git a/test/groovy/SeleniumExecuteTestsTest.groovy b/test/groovy/SeleniumExecuteTestsTest.groovy index 5b1872838..381b58145 100644 --- a/test/groovy/SeleniumExecuteTestsTest.groovy +++ b/test/groovy/SeleniumExecuteTestsTest.groovy @@ -57,6 +57,33 @@ class SeleniumExecuteTestsTest extends BasePiperTest { assertThat(dockerExecuteRule.dockerParams.sidecarVolumeBind, is(['/dev/shm': '/dev/shm'])) } + @Test + void testDockerFromCustomStepConfiguration() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '/path/to/workspace' + + nullScript.commonPipelineEnvironment.configuration = [steps:[seleniumExecuteTests:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]] + + stepRule.step.seleniumExecuteTests( + script: nullScript, + juStabUtils: utils + ) { + } + + assert expectedImage == dockerExecuteRule.dockerParams.dockerImage + assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions + assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars) + assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace + } + @Test void testExecuteSeleniumCustomBuildTool() { stepRule.step.seleniumExecuteTests( diff --git a/test/groovy/SnykExecuteTest.groovy b/test/groovy/SnykExecuteTest.groovy index d9b3e456b..1833c238d 100644 --- a/test/groovy/SnykExecuteTest.groovy +++ b/test/groovy/SnykExecuteTest.groovy @@ -17,6 +17,8 @@ import util.JenkinsStepRule import util.JenkinsLoggingRule import util.Rules +import com.sap.piper.MapUtils + class SnykExecuteTest extends BasePiperTest { private ExpectedException thrown = ExpectedException.none() private JenkinsDockerExecuteRule dockerExecuteRule = new JenkinsDockerExecuteRule(this) @@ -94,6 +96,35 @@ class SnykExecuteTest extends BasePiperTest { assertThat(dockerExecuteRule.dockerParams.stashContent, hasItem('opensourceConfiguration')) } + @Test + void testDockerFromCustomStepConfiguration() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['SNYK_TOKEN':'', 'env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '/path/to/workspace' + + + nullScript.commonPipelineEnvironment.configuration = MapUtils.merge( + nullScript.commonPipelineEnvironment.configuration, + [steps:[snykExecute:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]]) + + stepRule.step.snykExecute( + script: nullScript, + juStabUtils: utils + ) + + assert expectedImage == dockerExecuteRule.dockerParams.dockerImage + assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions + assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars) + assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace + } + @Test void testScanTypeNpm() throws Exception { stepRule.step.snykExecute( diff --git a/test/groovy/WhitesourceExecuteScanTest.groovy b/test/groovy/WhitesourceExecuteScanTest.groovy index 59e440692..b3f737d0a 100644 --- a/test/groovy/WhitesourceExecuteScanTest.groovy +++ b/test/groovy/WhitesourceExecuteScanTest.groovy @@ -2,6 +2,7 @@ import com.sap.piper.DescriptorUtils import com.sap.piper.JsonUtils import com.sap.piper.integration.WhitesourceOrgAdminRepository import com.sap.piper.integration.WhitesourceRepository +import com.sap.piper.MapUtils import hudson.AbortException import org.hamcrest.Matchers import org.junit.Assert @@ -100,6 +101,53 @@ class WhitesourceExecuteScanTest extends BasePiperTest { nullScript.commonPipelineEnvironment.configuration['steps']['whitesourceExecuteScan']['userTokenCredentialsId'] = 'ID-123456789' } + @Test + void testDockerFromCustomStepConfiguration() { + + def expectedImage = 'image:test' + def expectedEnvVars = ['env1': 'value1', 'env2': 'value2'] + def expectedOptions = '--opt1=val1 --opt2=val2 --opt3' + def expectedWorkspace = '/path/to/workspace' + + helper.registerAllowedMethod("readProperties", [Map], { + def result = new Properties() + result.putAll([ + "apiKey": "b39d1328-52e2-42e3-98f0-932709daf3f0", + "productName": "SHC - Piper", + "checkPolicies": "true", + "projectName": "python-test", + "projectVersion": "1.0.0" + ]) + return result + }) + + nullScript.commonPipelineEnvironment.configuration = + MapUtils.merge(nullScript.commonPipelineEnvironment.configuration, + [steps:[whitesourceExecuteScan:[ + dockerImage: expectedImage, + dockerOptions: expectedOptions, + dockerEnvVars: expectedEnvVars, + dockerWorkspace: expectedWorkspace + ]]] + ) + + stepRule.step.whitesourceExecuteScan([ + script : nullScript, + whitesourceRepositoryStub : whitesourceStub, + whitesourceOrgAdminRepositoryStub : whitesourceOrgAdminRepositoryStub, + descriptorUtilsStub : descriptorUtilsStub, + scanType : 'maven', + juStabUtils : utils, + orgToken : 'testOrgToken', + whitesourceProductName : 'testProduct' + ]) + + assert expectedImage == dockerExecuteRule.dockerParams.dockerImage + assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions + assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars) + assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace + } + @Test void testMaven() { helper.registerAllowedMethod("readProperties", [Map], { diff --git a/vars/batsExecuteTests.groovy b/vars/batsExecuteTests.groovy index 5f59122f3..099fd570c 100644 --- a/vars/batsExecuteTests.groovy +++ b/vars/batsExecuteTests.groovy @@ -16,6 +16,10 @@ import groovy.transform.Field /** @see dockerExecute */ 'dockerImage', /** @see dockerExecute */ + 'dockerEnvVars', + /** @see dockerExecute */ + 'dockerOptions', + /** @see dockerExecute */ 'dockerWorkspace', /** @see dockerExecute */ 'stashContent', @@ -97,7 +101,14 @@ void call(Map parameters = [:]) { } finally { sh "cat 'TEST-${config.testPackage}.tap'" if (config.outputFormat == 'junit') { - dockerExecute(script: script, dockerImage: config.dockerImage, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent) { + dockerExecute( + script: script, + dockerImage: config.dockerImage, + dockerEnvVars: config.dockerEnvVars, + dockerOptions: config.dockerOptions, + dockerWorkspace: config.dockerWorkspace, + stashContent: config.stashContent + ) { sh "NPM_CONFIG_PREFIX=~/.npm-global npm install tap-xunit -g" sh "cat 'TEST-${config.testPackage}.tap' | PATH=\$PATH:~/.npm-global/bin tap-xunit --package='${config.testPackage}' > TEST-${config.testPackage}.xml" } diff --git a/vars/gaugeExecuteTests.groovy b/vars/gaugeExecuteTests.groovy index 1eacde6ae..d07a5f3d4 100644 --- a/vars/gaugeExecuteTests.groovy +++ b/vars/gaugeExecuteTests.groovy @@ -24,6 +24,8 @@ import groovy.transform.Field 'dockerImage', /** @see dockerExecute*/ 'dockerName', + /** @see dockerExecute */ + 'dockerOptions', /** @see dockerExecute*/ 'dockerWorkspace', /** @@ -100,6 +102,8 @@ void call(Map parameters = [:]) { .mixin(parameters, PARAMETER_KEYS) .dependingOn('buildTool').mixin('dockerImage') .dependingOn('buildTool').mixin('dockerName') + .dependingOn('buildTool').mixin('dockerOptions') + .dependingOn('buildTool').mixin('dockerEnvVars') .dependingOn('buildTool').mixin('dockerWorkspace') .dependingOn('buildTool').mixin('languageRunner') .dependingOn('buildTool').mixin('runCommand') @@ -127,9 +131,10 @@ void call(Map parameters = [:]) { seleniumExecuteTests ( script: script, buildTool: config.buildTool, - dockerEnvVars: config.dockerEnvVars, dockerImage: config.dockerImage, dockerName: config.dockerName, + dockerEnvVars: config.dockerEnvVars, + dockerOptions: config.dockerOptions, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent ) { diff --git a/vars/karmaExecuteTests.groovy b/vars/karmaExecuteTests.groovy index 6202a7e11..7c4e86ced 100644 --- a/vars/karmaExecuteTests.groovy +++ b/vars/karmaExecuteTests.groovy @@ -30,6 +30,8 @@ import groovy.transform.Field * Specifies a dedicated user home directory for the container which will be passed as value for environment variable `HOME`. */ 'dockerWorkspace', + /** @see dockerExecute */ + 'dockerOptions', /** * With `failOnError` the behavior in case tests fail can be defined. * @possibleValues `true`, `false` @@ -95,6 +97,7 @@ void call(Map parameters = [:]) { dockerImage: config.dockerImage, dockerName: config.dockerName, dockerWorkspace: config.dockerWorkspace, + dockerOptions: config.dockerOptions, failOnError: config.failOnError, sidecarEnvVars: config.sidecarEnvVars, sidecarImage: config.sidecarImage, diff --git a/vars/mtaBuild.groovy b/vars/mtaBuild.groovy index 0253c8db2..07fcba90d 100644 --- a/vars/mtaBuild.groovy +++ b/vars/mtaBuild.groovy @@ -21,6 +21,12 @@ import static com.sap.piper.Utils.downloadSettingsFromUrl 'buildTarget', /** @see dockerExecute */ 'dockerImage', + /** @see dockerExecute */ + 'dockerEnvVars', + /** @see dockerExecute */ + 'dockerOptions', + /** @see dockerExecute */ + 'dockerWorkspace', /** The path to the extension descriptor file.*/ 'extension', /** @@ -34,8 +40,6 @@ import static com.sap.piper.Utils.downloadSettingsFromUrl 'projectSettingsFile' ] @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([ - /** @see dockerExecute */ - 'dockerOptions', /** Url to the npm registry that should be used for installing npm dependencies.*/ 'defaultNpmRegistry' ]) @@ -64,7 +68,13 @@ void call(Map parameters = [:]) { stepParam1: parameters?.script == null ], configuration) - dockerExecute(script: script, dockerImage: configuration.dockerImage, dockerOptions: configuration.dockerOptions) { + dockerExecute( + script: script, + dockerImage: configuration.dockerImage, + dockerEnvVars: configuration.dockerEnvVars, + dockerOptions: configuration.dockerOptions, + dockerWorkspace: configuration.dockerWorkspace + ) { String projectSettingsFile = configuration.projectSettingsFile?.trim() if (projectSettingsFile) { diff --git a/vars/newmanExecute.groovy b/vars/newmanExecute.groovy index f58a1eb53..3ac35c408 100644 --- a/vars/newmanExecute.groovy +++ b/vars/newmanExecute.groovy @@ -14,6 +14,12 @@ import groovy.transform.Field @Field Set STEP_CONFIG_KEYS = [ /** @see dockerExecute */ 'dockerImage', + /** @see dockerExecute*/ + 'dockerEnvVars', + /** @see dockerExecute */ + 'dockerOptions', + /** @see dockerExecute*/ + 'dockerWorkspace', /** * Defines the behavior, in case tests fail. * @possibleValues `true`, `false` @@ -103,6 +109,9 @@ void call(Map parameters = [:]) { dockerExecute( script: script, dockerImage: config.dockerImage, + dockerEnvVars: config.dockerEnvVars, + dockerOptions: config.dockerOptions, + dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent ) { sh "NPM_CONFIG_PREFIX=~/.npm-global ${config.newmanInstallCommand}" diff --git a/vars/npmExecute.groovy b/vars/npmExecute.groovy index 06e980737..52aa94359 100644 --- a/vars/npmExecute.groovy +++ b/vars/npmExecute.groovy @@ -11,6 +11,12 @@ import groovy.transform.Field * Name of the docker image that should be used, in which node should be installed and configured. Default value is 'node:8-stretch'. */ 'dockerImage', + /** @see dockerExecute*/ + 'dockerEnvVars', + /** @see dockerExecute */ + 'dockerOptions', + /** @see dockerExecute*/ + 'dockerWorkspace', /** * URL of default NPM registry */ @@ -53,7 +59,12 @@ void call(Map parameters = [:], body = null) { if (!fileExists('package.json')) { error "[${STEP_NAME}] package.json is not found." } - dockerExecute(script: script, dockerImage: configuration.dockerImage, dockerOptions: configuration.dockerOptions) { + dockerExecute(script: script, + dockerImage: configuration.dockerImage, + dockerEnvVars: configuration.dockerEnvVars, + dockerOptions: configuration.dockerOptions, + dockerWorkspace: configuration.dockerWorkspace + ) { if (configuration.defaultNpmRegistry) { sh "npm config set registry ${configuration.defaultNpmRegistry}" } diff --git a/vars/seleniumExecuteTests.groovy b/vars/seleniumExecuteTests.groovy index 8f5f3b197..c1a889328 100644 --- a/vars/seleniumExecuteTests.groovy +++ b/vars/seleniumExecuteTests.groovy @@ -26,6 +26,8 @@ import groovy.text.SimpleTemplateEngine /** @see dockerExecute */ 'dockerName', /** @see dockerExecute */ + 'dockerOptions', + /** @see dockerExecute */ 'dockerWorkspace', /** * With `failOnError` the behavior in case tests fail can be defined. @@ -103,6 +105,7 @@ void call(Map parameters = [:], Closure body) { dockerEnvVars: config.dockerEnvVars, dockerImage: config.dockerImage, dockerName: config.dockerName, + dockerOptions: config.dockerOptions, dockerWorkspace: config.dockerWorkspace, sidecarEnvVars: config.sidecarEnvVars, sidecarImage: config.sidecarImage, diff --git a/vars/snykExecute.groovy b/vars/snykExecute.groovy index d82c383d2..72fbeefee 100644 --- a/vars/snykExecute.groovy +++ b/vars/snykExecute.groovy @@ -4,6 +4,7 @@ import com.sap.piper.ConfigurationHelper import com.sap.piper.GenerateDocumentation import com.sap.piper.Utils import com.sap.piper.mta.MtaMultiplexer +import com.sap.piper.MapUtils import groovy.transform.Field @@ -23,6 +24,12 @@ import groovy.transform.Field 'buildDescriptorFile', /** @see dockerExecute */ 'dockerImage', + /** @see dockerExecute*/ + 'dockerEnvVars', + /** @see dockerExecute */ + 'dockerOptions', + /** @see dockerExecute*/ + 'dockerWorkspace', /** * Only scanType 'mta': Exclude modules from MTA projects. */ @@ -103,8 +110,10 @@ void call(Map parameters = [:]) { dockerExecute( script: script, dockerImage: config.dockerImage, - stashContent: config.stashContent, - dockerEnvVars: ['SNYK_TOKEN': token] + dockerEnvVars: MapUtils.merge(['SNYK_TOKEN': token],config.dockerEnvVars?:[:]), + dockerWorkspace: config.dockerWorkspace, + dockerOptions: config.dockerOptions, + stashContent: config.stashContent ) { // install Snyk sh 'npm install snyk --global --quiet' diff --git a/vars/whitesourceExecuteScan.groovy b/vars/whitesourceExecuteScan.groovy index c7c0cfd21..10381775a 100644 --- a/vars/whitesourceExecuteScan.groovy +++ b/vars/whitesourceExecuteScan.groovy @@ -117,6 +117,10 @@ import static com.sap.piper.Prerequisites.checkScript * Docker workspace to be used for scanning. */ 'dockerWorkspace', + /** @see dockerExecute*/ + 'dockerEnvVars', + /** @see dockerExecute */ + 'dockerOptions', /** * Whether license compliance is considered and reported as part of the assessment. * @possibleValues `true`, `false` @@ -246,6 +250,8 @@ void call(Map parameters = [:]) { .dependingOn('scanType').mixin('buildDescriptorFile') .dependingOn('scanType').mixin('dockerImage') .dependingOn('scanType').mixin('dockerWorkspace') + .dependingOn('scanType').mixin('dockerOptions') + .dependingOn('scanType').mixin('dockerEnvVars') .dependingOn('scanType').mixin('stashContent') .dependingOn('scanType').mixin('whitesource/configFilePath') .dependingOn('scanType').mixin('whitesource/installCommand') @@ -369,7 +375,14 @@ private def triggerWhitesourceScanWithUserKey(script, config, utils, descriptorU script.commonPipelineEnvironment.getValue('whitesourceProjectNames').add(projectName) WhitesourceConfigurationHelper.extendUAConfigurationFile(script, utils, config, path) - dockerExecute(script: script, dockerImage: config.dockerImage, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent) { + dockerExecute( + script: script, + dockerImage: config.dockerImage, + dockerEnvVars: config.dockerEnvVars, + dockerOptions: config.dockerOptions, + dockerWorkspace: config.dockerWorkspace, + stashContent: config.stashContent + ) { if (config.whitesource.agentDownloadUrl) { def agentDownloadUrl = new GStringTemplateEngine().createTemplate(config.whitesource.agentDownloadUrl).make([config: config]).toString() //if agentDownloadUrl empty, rely on dockerImage to contain unifiedAgent correctly set up and available From db8f9d0f0775c50afff2c1b445584669ec321dee Mon Sep 17 00:00:00 2001 From: Roland Stengel Date: Thu, 25 Jul 2019 12:12:34 +0200 Subject: [PATCH 2/2] harmonize docker configuration properties fixes --- test/groovy/GaugeExecuteTestsTest.groovy | 2 -- vars/npmExecute.groovy | 4 ++-- vars/whitesourceExecuteScan.groovy | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/groovy/GaugeExecuteTestsTest.groovy b/test/groovy/GaugeExecuteTestsTest.groovy index f0883e5f0..31e60c03a 100644 --- a/test/groovy/GaugeExecuteTestsTest.groovy +++ b/test/groovy/GaugeExecuteTestsTest.groovy @@ -12,7 +12,6 @@ class GaugeExecuteTestsTest extends BasePiperTest { private JenkinsStepRule stepRule = new JenkinsStepRule(this) private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this) - private JenkinsDockerExecuteRule dockerExecuteRule = new JenkinsDockerExecuteRule(this) private JenkinsEnvironmentRule environmentRule = new JenkinsEnvironmentRule(this) private ExpectedException thrown = ExpectedException.none() @@ -22,7 +21,6 @@ class GaugeExecuteTestsTest extends BasePiperTest { .around(new JenkinsReadYamlRule(this)) .around(shellRule) .around(loggingRule) - .around(dockerExecuteRule) .around(environmentRule) .around(stepRule) .around(thrown) diff --git a/vars/npmExecute.groovy b/vars/npmExecute.groovy index 52aa94359..30baf998c 100644 --- a/vars/npmExecute.groovy +++ b/vars/npmExecute.groovy @@ -59,8 +59,8 @@ void call(Map parameters = [:], body = null) { if (!fileExists('package.json')) { error "[${STEP_NAME}] package.json is not found." } - dockerExecute(script: script, - dockerImage: configuration.dockerImage, + dockerExecute(script: script, + dockerImage: configuration.dockerImage, dockerEnvVars: configuration.dockerEnvVars, dockerOptions: configuration.dockerOptions, dockerWorkspace: configuration.dockerWorkspace diff --git a/vars/whitesourceExecuteScan.groovy b/vars/whitesourceExecuteScan.groovy index 10381775a..d4a975a23 100644 --- a/vars/whitesourceExecuteScan.groovy +++ b/vars/whitesourceExecuteScan.groovy @@ -376,7 +376,7 @@ private def triggerWhitesourceScanWithUserKey(script, config, utils, descriptorU WhitesourceConfigurationHelper.extendUAConfigurationFile(script, utils, config, path) dockerExecute( - script: script, + script: script, dockerImage: config.dockerImage, dockerEnvVars: config.dockerEnvVars, dockerOptions: config.dockerOptions,