diff --git a/.codeclimate.yml b/.codeclimate.yml index 9b68739e4..f16213b9a 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,6 +1,9 @@ plugins: codenarc: enabled: true + checks: + BooleanGetBoolean: + enabled: false editorconfig: enabled: true checks: diff --git a/README.md b/README.md index 047fce3f5..d832e97f2 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ To setup the shared library, you need to perform the following steps: 1. Open the system configuration page (*Manage Jenkins > Configure System*). 1. Scroll down to section *Global Pipeline Libraries* and add a new Library by clicking the *Add* button. - 1. set *Library Name* to `piper-library-os` + 1. set *Library Name* to `piper-lib-os` 1. set *Default Version* to the branch or tag you want to consume (e.g. `master` or `v0.1`) 1. set *Retrieval Method* to `Modern SCM` @@ -82,11 +82,11 @@ To setup the shared library, you need to perform the following steps: ![Library Setup](./documentation/docs/images/setupInJenkins.png) -Now the library is available as `piper-library-os` and can be used in any +Now the library is available as `piper-lib-os` and can be used in any `Jenkinsfile` by adding this line: ```groovy -@Library('piper-library-os') _ +@Library('piper-lib-os') _ ``` Jenkins will download the library during execution of the `Jenkinsfile`. diff --git a/createDocu.groovy b/createDocu.groovy index 5b1f52e87..2d76e9536 100644 --- a/createDocu.groovy +++ b/createDocu.groovy @@ -44,7 +44,7 @@ class TemplateHelper { parameters.keySet().toSorted().each { def props = parameters.get(it) - t += "| `${it}` | ${props.required ? 'yes' : 'no'} | ${(props.defaultValue ? '`' + props.defaultValue + '`' : '') } | ${props.value ?: ''} |\n" + t += "| `${it}` | ${props.mandatory ?: props.required ? 'yes' : 'no'} | ${(props.defaultValue ? '`' + props.defaultValue + '`' : '') } | ${props.value ?: ''} |\n" } t @@ -65,7 +65,7 @@ class TemplateHelper { def t = '''| |We recommend to define values of step parameters via [config.yml file](../configuration.md). | - |In following sections the configuration is possible:'''.stripMargin() + |In following sections the configuration is possible:\n\n'''.stripMargin() t += '| parameter | general | step | stage |\n' t += '|-----------|---------|------|-------|\n' @@ -91,7 +91,7 @@ class Helper { new GroovyClassLoader(classLoader, compilerConfig, true) .parseClass(new File('src/com/sap/piper/ConfigurationHelper.groovy')) - .newInstance(script, [:]) + .newInstance(script, [:]).loadStepDefaults() } static getPrepareDefaultValuesStep(def gse) { @@ -195,9 +195,10 @@ class Helper { boolean docu = false, value = false, + mandatory = false, docuEnd = false - def docuLines = [], valueLines = [] + def docuLines = [], valueLines = [], mandatoryLines = [] f.eachLine { line -> @@ -221,14 +222,17 @@ class Helper { if(step.parameters[param].docu || step.parameters[param].value) System.err << "[WARNING] There is already some documentation for parameter '${param}. Is this parameter documented twice?'\n" - def _docu = [], _value = [] + def _docu = [], _value = [], _mandatory = [] docuLines.each { _docu << it } valueLines.each { _value << it} + mandatoryLines.each { _mandatory << it} step.parameters[param].docu = _docu*.trim().join(' ').trim() step.parameters[param].value = _value*.trim().join(' ').trim() + step.parameters[param].mandatory = _mandatory*.trim().join(' ').trim() } docuLines.clear() valueLines.clear() + mandatoryLines.clear() } if( line.trim() ==~ /^\/\*\*/ ) { @@ -242,15 +246,30 @@ class Helper { if(_line.startsWith('*/')) _line = _line.replaceAll('^\\*/', '') // end comment if(_line.startsWith('*')) _line = _line.replaceAll('^\\*', '') // continue comment if(_line ==~ /.*@possibleValues.*/) { + mandatory = false // should be something like reset attributes value = true } + // some remark for mandatory e.g. some parameters are only mandatory under certain conditions + if(_line ==~ /.*@mandatory.*/) { + value = false // should be something like reset attributes ... + mandatory = true + } if(value) { if(_line) { _line = (_line =~ /.*@possibleValues\s*?(.*)/)[0][1] valueLines << _line } - } else { + } + + if(mandatory) { + if(_line) { + _line = (_line =~ /.*@mandatory\s*?(.*)/)[0][1] + mandatoryLines << _line + } + } + + if(! value && ! mandatory) { docuLines << _line.trim() } } @@ -258,14 +277,15 @@ class Helper { if(docu && line.trim() ==~ /^\*\//) { docu = false value = false + mandatory = false docuEnd = true } } } private static isHeader(line) { - Matcher headerMatcher = (line =~ /(def|void)\s*call\s*\(/ ) - return headerMatcher.size() == 1 && headerMatcher[0].size() == 2 + Matcher headerMatcher = (line =~ /(?:(?:def|void)\s*call\s*\()|(?:@.*)/ ) + return headerMatcher.size() == 1 } private static retrieveParameterName(line) { @@ -465,7 +485,7 @@ def handleStep(stepName, prepareDefaultValuesStep, gse) { step.parameters['script'] = [ docu: 'The common script environment of the Jenkinsfile running. ' + 'Typically the reference to the script calling the pipeline ' + - 'step is provided with the this parameter, as in script: this. ' + + 'step is provided with the this parameter, as in `script: this`. ' + 'This allows the function to access the ' + 'commonPipelineEnvironment for retrieving, for example, configuration parameters.', required: true, diff --git a/documentation/docs/images/setupInJenkins.png b/documentation/docs/images/setupInJenkins.png index f19ac41ca..c283fee7b 100755 Binary files a/documentation/docs/images/setupInJenkins.png and b/documentation/docs/images/setupInJenkins.png differ diff --git a/documentation/docs/steps/checkChangeInDevelopment.md b/documentation/docs/steps/checkChangeInDevelopment.md index a850cfa07..f3562bc3e 100644 --- a/documentation/docs/steps/checkChangeInDevelopment.md +++ b/documentation/docs/steps/checkChangeInDevelopment.md @@ -42,7 +42,7 @@ The step is configured using a customer configuration file provided as resource in an custom shared library. ```groovy -@Library('piper-library-os@master') _ +@Library('piper-lib-os@master') _ // the shared lib containing the additional configuration // needs to be configured in Jenkins diff --git a/documentation/docs/steps/cloudFoundryDeploy.md b/documentation/docs/steps/cloudFoundryDeploy.md index 78c0feb12..bf0e58db2 100644 --- a/documentation/docs/steps/cloudFoundryDeploy.md +++ b/documentation/docs/steps/cloudFoundryDeploy.md @@ -29,6 +29,7 @@ Deployment can be done | cloudFoundry | yes | | | | deployTool | no | cf_native | cf_native, mtaDeployPlugin | | deployType | no | standard | standard, blue-green | +| keepOldInstance | no | false | true, false | | dockerImage | no | s4sdk/docker-cf-cli | | | dockerWorkspace | no | /home/piper | | | mtaDeployParameters | | -f | | @@ -65,6 +66,7 @@ Deployment can be done * `deployTool` defines the tool which should be used for deployment. * `deployType` defines the type of deployment, either `standard` deployment which results in a system downtime or a zero-downtime `blue-green` deployment. +* `keepOldInstance` in case of a `blue-green` deployment the old instance will be deleted by default. If this option is set to true the old instance will remain stopped in the Cloud Foundry space. * `dockerImage` defines the Docker image containing the deployment tools (like cf cli, ...) and `dockerWorkspace` defines the home directory of the default user of the `dockerImage` * `smokeTestScript` allows to specify a script which performs a check during blue-green deployment. The script gets the FQDN as parameter and returns `exit code 0` in case check returned `smokeTestStatusCode`. More details can be found [here](https://github.com/bluemixgaragelondon/cf-blue-green-deploy#how-to-use)
Currently this option is only considered for deployTool `cf_native`. * `stashContent` defines the stash names which should be unstashed at the beginning of the step. This makes the files available in case the step is started on an empty node. diff --git a/documentation/docs/steps/karmaExecuteTests.md b/documentation/docs/steps/karmaExecuteTests.md index 856e09787..11015922a 100644 --- a/documentation/docs/steps/karmaExecuteTests.md +++ b/documentation/docs/steps/karmaExecuteTests.md @@ -25,7 +25,7 @@ In the Docker network, the containers can be referenced by the values provided i | ----------|-----------|---------|-----------------| |script|yes||| |containerPortMappings|no|`[node:8-stretch: [[containerPort: 9876, hostPort: 9876]]]`|| -|dockerEnvVars|no||| +|dockerEnvVars|no|`[ NO_PROXY: 'localhost,karma,$NO_PROXY', no_proxy: 'localhost,karma,$no_proxy']`|| |dockerImage|no|`node:8-stretch`|| |dockerName|no|`karma`|| |dockerWorkspace|no|`/home/node`|| @@ -33,11 +33,11 @@ In the Docker network, the containers can be referenced by the values provided i |installCommand|no|`npm install --quiet`|| |modules|no|`['.']`|| |runCommand|no|`npm run karma`|| -|sidecarEnvVars|no||| +|sidecarEnvVars|no|`[ NO_PROXY: 'localhost,selenium,$NO_PROXY', no_proxy: 'localhost,selenium,$no_proxy']`|| |sidecarImage|no||| |sidecarName|no||| |sidecarVolumeBind|no||| -|stashContent|no||| +|stashContent|no|`['buildDescriptor', 'tests']`|| - `script` - defines the global script environment of the Jenkinsfile run. Typically `this` is passed to this parameter. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for storing the measured duration. - `containerPortMappings` - see step [dockerExecute](dockerExecute.md) diff --git a/documentation/docs/steps/testsPublishResults.md b/documentation/docs/steps/testsPublishResults.md index 17f083978..5270af979 100644 --- a/documentation/docs/steps/testsPublishResults.md +++ b/documentation/docs/steps/testsPublishResults.md @@ -54,7 +54,7 @@ Each of the parameters `junit`, `jacoco`, `cobertura` and `jmeter` can be set to | parameter | mandatory | default | possible values | | ----------|-----------|---------|-----------------| -| pattern | no | `'**/target/surefire-reports/*.xml'` | | +| pattern | no | `'**/TEST-*.xml'` | | | archive | no | `false` | true, false | | updateResults | no | `false` | true, false | | allowEmptyResults | no | `true` | true, false | diff --git a/documentation/docs/steps/transportRequestCreate.md b/documentation/docs/steps/transportRequestCreate.md index a5f44a865..31ec813c1 100644 --- a/documentation/docs/steps/transportRequestCreate.md +++ b/documentation/docs/steps/transportRequestCreate.md @@ -7,6 +7,8 @@ Creates * a Transport Request for a Change Document on the Solution Manager (type `SOLMAN`) or * a Transport Request inside an ABAP system (type`CTS`) +The id of the transport request is availabe via [commonPipelineEnvironment.getTransportRequestId()](commonPipelineEnvironment.md) + ## Prerequisites * **[Change Management Client 2.0.0 or compatible version](http://central.maven.org/maven2/com/sap/devops/cmclient/dist.cli/)** - available for download on Maven Central. @@ -49,7 +51,7 @@ The step is configured using a customer configuration file provided as resource in an custom shared library. ```groovy -@Library('piper-library-os@master') _ +@Library('piper-lib-os@master') _ // the shared lib containing the additional configuration // needs to be configured in Jenkins @@ -97,7 +99,7 @@ The parameters can also be provided when the step is invoked. For examples see b ## Return value -The id of the Transport Request that has been created. +none ## Exceptions diff --git a/documentation/docs/steps/transportRequestRelease.md b/documentation/docs/steps/transportRequestRelease.md index 0cfded3be..45c527712 100644 --- a/documentation/docs/steps/transportRequestRelease.md +++ b/documentation/docs/steps/transportRequestRelease.md @@ -41,7 +41,7 @@ The step is configured using a customer configuration file provided as resource in an custom shared library. ```groovy -@Library('piper-library-os@master') _ +@Library('piper-lib-os@master') _ // the shared lib containing the additional configuration // needs to be configured in Jenkins diff --git a/documentation/docs/steps/transportRequestUploadFile.md b/documentation/docs/steps/transportRequestUploadFile.md index b0b0b28b3..c9cb50c4e 100644 --- a/documentation/docs/steps/transportRequestUploadFile.md +++ b/documentation/docs/steps/transportRequestUploadFile.md @@ -46,7 +46,7 @@ The step is configured using a customer configuration file provided as resource in an custom shared library. ```groovy -@Library('piper-library-os@master') _ +@Library('piper-lib-os@master') _ // the shared lib containing the additional configuration // needs to be configured in Jenkins diff --git a/resources/default_pipeline_environment.yml b/resources/default_pipeline_environment.yml index 562d88537..877a1461c 100644 --- a/resources/default_pipeline_environment.yml +++ b/resources/default_pipeline_environment.yml @@ -123,6 +123,7 @@ steps: apiEndpoint: 'https://api.cf.eu10.hana.ondemand.com' deployTool: 'cf_native' deployType: 'standard' + keepOldInstance: false mtaDeployParameters: '-f' mtaExtensionDescriptor: '' mtaPath: '' @@ -187,6 +188,9 @@ steps: 'node:8-stretch': - containerPort: 9876 hostPort: 9876 + dockerEnvVars: + NO_PROXY: 'localhost,selenium,$NO_PROXY' + no_proxy: 'localhost,selenium,$no_proxy' dockerImage: 'node:8-stretch' dockerName: 'karma' dockerWorkspace: '/home/node' @@ -194,6 +198,12 @@ steps: modules: - '.' runCommand: 'npm run karma' + sidecarEnvVars: + NO_PROXY: 'localhost,karma,$NO_PROXY' + no_proxy: 'localhost,karma,$no_proxy' + stashContent: + - buildDescriptor + - tests mailSendNotification: notificationAttachment: true notifyCulprits: true @@ -217,7 +227,8 @@ steps: newmanCollection: '**/*.postman_collection.json' newmanEnvironment: '' newmanGlobals: '' - newmanRunCommand: "run ${config.newmanCollection} --environment '${config.newmanEnvironment}' --globals '${config.newmanGlobals}' --reporters junit,html --reporter-junit-export target/newman/TEST-${collectionDisplayName}.xml --reporter-html-export target/newman/TEST-${collectionDisplayName}.html" + newmanInstallCommand: 'npm install newman newman-reporter-html --global --quiet' + newmanRunCommand: "run '${config.newmanCollection}' --environment '${config.newmanEnvironment}' --globals '${config.newmanGlobals}' --reporters junit,html --reporter-junit-export 'target/newman/TEST-${collectionDisplayName}.xml' --reporter-html-export 'target/newman/TEST-${collectionDisplayName}.html'" stashContent: - 'tests' pipelineRestartSteps: @@ -287,7 +298,7 @@ steps: toHtml: false testsPublishResults: junit: - pattern: '**/target/surefire-reports/*.xml' + pattern: '**/TEST-*.xml' updateResults: false allowEmptyResults: true archive: false diff --git a/src/com/sap/piper/cm/StepHelpers.groovy b/src/com/sap/piper/cm/StepHelpers.groovy index cc0bfc27d..7b0c21eef 100644 --- a/src/com/sap/piper/cm/StepHelpers.groovy +++ b/src/com/sap/piper/cm/StepHelpers.groovy @@ -4,57 +4,64 @@ import com.cloudbees.groovy.cps.NonCPS public class StepHelpers { - @NonCPS - public static def getTransportRequestId(ChangeManagement cm, def step, Map configuration) { + public static def getTransportRequestId(ChangeManagement cm, def script, Map configuration) { def transportRequestId = configuration.transportRequestId if(transportRequestId?.trim()) { - step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters." + script.echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters." + return transportRequestId - } else { - - step.echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - " Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'." - - try { - transportRequestId = cm.getTransportRequestId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.transportRequestLabel, - configuration.changeManagement.git.format - ) - - step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history" - - } catch(ChangeManagementException ex) { - step.echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}." - } } - return transportRequestId + + transportRequestId = script.commonPipelineEnvironment.getTransportRequestId() + + if(transportRequestId?.trim()) { + script.echo "[INFO] Transport request id '${transportRequestId}' retrieved from common pipeline environment." + return transportRequestId + } + + script.echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + + " Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'." + + try { + transportRequestId = cm.getTransportRequestId( + configuration.changeManagement.git.from, + configuration.changeManagement.git.to, + configuration.changeManagement.transportRequestLabel, + configuration.changeManagement.git.format + ) + + script.commonPipelineEnvironment.setTransportRequestId(transportRequestId) + script.echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history" + + } catch(ChangeManagementException ex) { + script.echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}." + } + + transportRequestId } - @NonCPS - public static getChangeDocumentId(ChangeManagement cm, def step, Map configuration) { + public static getChangeDocumentId(ChangeManagement cm, def script, Map configuration) { def changeDocumentId = configuration.changeDocumentId if(changeDocumentId?.trim()) { - step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters." + script.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters." return changeDocumentId } - changeDocumentId = step.commonPipelineEnvironment.getChangeDocumentId() + changeDocumentId = script.commonPipelineEnvironment.getChangeDocumentId() if(changeDocumentId?.trim()) { - step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from common pipeline environment." + script.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from common pipeline environment." return changeDocumentId } - step.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + + script.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + "Searching for pattern '${configuration.changeManagement.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." try { @@ -65,31 +72,31 @@ public class StepHelpers { configuration.changeManagement.git.format ) - step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" - step.commonPipelineEnvironment.setChangeDocumentId(changeDocumentId) + script.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" + script.commonPipelineEnvironment.setChangeDocumentId(changeDocumentId) } catch(ChangeManagementException ex) { - step.echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}." + script.echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}." } return changeDocumentId } @NonCPS - static BackendType getBackendTypeAndLogInfoIfCMIntegrationDisabled(def step, Map configuration) { + static BackendType getBackendTypeAndLogInfoIfCMIntegrationDisabled(def script, Map configuration) { BackendType backendType try { backendType = configuration.changeManagement.type as BackendType } catch(IllegalArgumentException e) { - step.error "Invalid backend type: '${configuration.changeManagement.type}'. " + + script.error "Invalid backend type: '${configuration.changeManagement.type}'. " + "Valid values: [${BackendType.values().join(', ')}]. " + "Configuration: 'changeManagement/type'." } if (backendType == BackendType.NONE) { - step.echo "[INFO] Change management integration intentionally switched off. " + + script.echo "[INFO] Change management integration intentionally switched off. " + "In order to enable it provide 'changeManagement/type with one of " + "[${BackendType.values().minus(BackendType.NONE).join(', ')}] and maintain " + "other required properties like 'endpoint', 'credentialsId'." diff --git a/test/groovy/CloudFoundryDeployTest.groovy b/test/groovy/CloudFoundryDeployTest.groovy index a0ce33db2..ccfc9b6e7 100644 --- a/test/groovy/CloudFoundryDeployTest.groovy +++ b/test/groovy/CloudFoundryDeployTest.groovy @@ -19,6 +19,7 @@ import util.Rules import static org.junit.Assert.assertThat import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.not import static org.hamcrest.Matchers.hasEntry import static org.hamcrest.Matchers.containsString @@ -126,6 +127,7 @@ class CloudFoundryDeployTest extends BasePiperTest { assertThat(jedr.dockerParams.dockerEnvVars, hasEntry('STATUS_CODE', "${200}")) assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"'))) assertThat(jscr.shell, hasItem(containsString("cf push testAppName -f 'test.yml'"))) + assertThat(jscr.shell, hasItem(containsString("cf logout"))) } @Test @@ -175,6 +177,7 @@ class CloudFoundryDeployTest extends BasePiperTest { assertThat(jedr.dockerParams.dockerEnvVars, hasEntry('STATUS_CODE', "${200}")) assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"'))) assertThat(jscr.shell, hasItem(containsString("cf push testAppName -f 'test.yml'"))) + assertThat(jscr.shell, hasItem(containsString("cf logout"))) } @Test @@ -198,6 +201,7 @@ class CloudFoundryDeployTest extends BasePiperTest { // asserts assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"'))) assertThat(jscr.shell, hasItem(containsString("cf push -f 'test.yml'"))) + assertThat(jscr.shell, hasItem(containsString("cf logout"))) } @Test @@ -223,7 +227,7 @@ class CloudFoundryDeployTest extends BasePiperTest { } @Test - void testCfNativeBlueGreen() { + void testCfNativeBlueGreenDefaultDeleteOldInstance() { jryr.registerYaml('test.yml', "applications: [[]]") @@ -244,8 +248,85 @@ class CloudFoundryDeployTest extends BasePiperTest { assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"'))) assertThat(jscr.shell, hasItem(containsString("cf blue-green-deploy testAppName --delete-old-apps -f 'test.yml'"))) + assertThat(jscr.shell, hasItem(containsString("cf logout"))) + } + @Test + void testCfNativeBlueGreenExplicitDeleteOldInstance() { + + jryr.registerYaml('test.yml', "applications: [[]]") + + jsr.step.cloudFoundryDeploy([ + script: nullScript, + juStabUtils: utils, + deployTool: 'cf_native', + deployType: 'blue-green', + keepOldInstance: false, + cfOrg: 'testOrg', + cfSpace: 'testSpace', + cfCredentialsId: 'test_cfCredentialsId', + cfAppName: 'testAppName', + cfManifest: 'test.yml' + ]) + + assertThat(jedr.dockerParams, hasEntry('dockerImage', 's4sdk/docker-cf-cli')) + assertThat(jedr.dockerParams, hasEntry('dockerWorkspace', '/home/piper')) + + assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"'))) + assertThat(jscr.shell, hasItem(containsString("cf blue-green-deploy testAppName --delete-old-apps -f 'test.yml'"))) + assertThat(jscr.shell, not(hasItem(containsString("cf stop testAppName-old")))) + assertThat(jscr.shell, hasItem(containsString("cf logout"))) + + } + + @Test + void testCfNativeBlueGreenKeepOldInstance() { + + jryr.registerYaml('test.yml', "applications: [[]]") + + jsr.step.cloudFoundryDeploy([ + script: nullScript, + juStabUtils: utils, + deployTool: 'cf_native', + deployType: 'blue-green', + keepOldInstance: true, + cfOrg: 'testOrg', + cfSpace: 'testSpace', + cfCredentialsId: 'test_cfCredentialsId', + cfAppName: 'testAppName', + cfManifest: 'test.yml' + ]) + + assertThat(jedr.dockerParams, hasEntry('dockerImage', 's4sdk/docker-cf-cli')) + assertThat(jedr.dockerParams, hasEntry('dockerWorkspace', '/home/piper')) + + assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"'))) + assertThat(jscr.shell, hasItem(containsString("cf blue-green-deploy testAppName -f 'test.yml'"))) + assertThat(jscr.shell, hasItem(containsString("cf stop testAppName-old"))) + assertThat(jscr.shell, hasItem(containsString("cf logout"))) + } + + @Test + void testCfNativeStandardShouldNotStopInstance() { + + jryr.registerYaml('test.yml', "applications: [[]]") + + jsr.step.cloudFoundryDeploy([ + script: nullScript, + juStabUtils: utils, + deployTool: 'cf_native', + deployType: 'standard', + keepOldInstance: true, + cfOrg: 'testOrg', + cfSpace: 'testSpace', + cfCredentialsId: 'test_cfCredentialsId', + cfAppName: 'testAppName', + cfManifest: 'test.yml' + ]) + + assertThat(jscr.shell, not(hasItem(containsString("cf stop testAppName-old")))) + } @Test void testCfNativeWithoutAppNameBlueGreen() { @@ -285,5 +366,6 @@ class CloudFoundryDeployTest extends BasePiperTest { assertThat(jedr.dockerParams, hasEntry('dockerWorkspace', '/home/piper')) assertThat(jscr.shell, hasItem(containsString('cf login -u test_cf -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"'))) assertThat(jscr.shell, hasItem(containsString('cf deploy target/test.mtar -f'))) + assertThat(jscr.shell, hasItem(containsString('cf logout'))) } } diff --git a/test/groovy/CommonStepsTest.groovy b/test/groovy/CommonStepsTest.groovy index da24a3c8f..1a950da76 100644 --- a/test/groovy/CommonStepsTest.groovy +++ b/test/groovy/CommonStepsTest.groovy @@ -216,7 +216,6 @@ public class CommonStepsTest extends BasePiperTest{ def stepsWithCallMethodsOtherThanVoid = [] def whitelist = [ - 'transportRequestCreate', 'durationMeasure', ] @@ -238,7 +237,7 @@ public class CommonStepsTest extends BasePiperTest{ private static getSteps() { List steps = [] new File('vars').traverse(type: FileType.FILES, maxDepth: 0) - { if(it.getName().endsWith('.groovy')) steps << (it =~ /vars\/(.*)\.groovy/)[0][1] } + { if(it.getName().endsWith('.groovy')) steps << (it =~ /vars[\\\/](.*)\.groovy/)[0][1] } return steps } } diff --git a/test/groovy/NeoDeployTest.groovy b/test/groovy/NeoDeployTest.groovy index 31f02581f..3041998d0 100644 --- a/test/groovy/NeoDeployTest.groovy +++ b/test/groovy/NeoDeployTest.groovy @@ -1,3 +1,4 @@ +import com.sap.piper.Utils import hudson.AbortException import org.junit.rules.TemporaryFolder @@ -6,6 +7,8 @@ import org.junit.BeforeClass import org.junit.ClassRule import org.junit.Ignore +import java.util.Map + import org.hamcrest.BaseMatcher import org.hamcrest.Description import org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException @@ -81,13 +84,25 @@ class NeoDeployTest extends BasePiperTest { @Test void straightForwardTestConfigViaConfigProperties() { + boolean buildStatusHasBeenSet = false + boolean notifyOldConfigFrameworkUsed = false + nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com') nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123') nullScript.commonPipelineEnvironment.configuration = [:] + nullScript.currentBuild = [setResult: {buildStatusHasBeenSet = true}] + + def utils = new Utils() { + void pushToSWA(Map parameters, Map config) { + notifyOldConfigFrameworkUsed = parameters.stepParam4 + } + } + jsr.step.neoDeploy(script: nullScript, archivePath: archiveName, - neoCredentialsId: 'myCredentialsId' + neoCredentialsId: 'myCredentialsId', + utils: utils ) Assert.assertThat(jscr.shell, @@ -98,14 +113,53 @@ class NeoDeployTest extends BasePiperTest { .hasSingleQuotedOption('user', 'anonymous') .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') .hasDoubleQuotedOption('source', '.*')) + + assert !buildStatusHasBeenSet + assert notifyOldConfigFrameworkUsed + } + + @Test + void testConfigViaConfigPropertiesSetsBuildToUnstable() { + + def buildStatus = 'SUCCESS' + + nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com') + nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123') + nullScript.commonPipelineEnvironment.configuration = [:] + + nullScript.currentBuild = [setResult: { r -> buildStatus = r}] + + System.setProperty('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy', + Boolean.TRUE.toString()) + + try { + jsr.step.neoDeploy(script: nullScript, + archivePath: archiveName, + neoCredentialsId: 'myCredentialsId', + utils: utils + ) + } finally { + System.clearProperty('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy') + } + + assert buildStatus == 'UNSTABLE' } @Test void straightForwardTestConfigViaConfiguration() { + boolean notifyOldConfigFrameworkUsed = true + + def utils = new Utils() { + void pushToSWA(Map parameters, Map config) { + notifyOldConfigFrameworkUsed = parameters.stepParam4 + } + } + jsr.step.neoDeploy(script: nullScript, archivePath: archiveName, - neoCredentialsId: 'myCredentialsId' + neoCredentialsId: 'myCredentialsId', + utils: utils, ) Assert.assertThat(jscr.shell, @@ -116,6 +170,8 @@ class NeoDeployTest extends BasePiperTest { .hasSingleQuotedOption('user', 'anonymous') .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') .hasDoubleQuotedOption('source', '.*')) + + assert !notifyOldConfigFrameworkUsed } @Test diff --git a/test/groovy/NewmanExecuteTest.groovy b/test/groovy/NewmanExecuteTest.groovy index df76cb9f2..b4a9dc37f 100644 --- a/test/groovy/NewmanExecuteTest.groovy +++ b/test/groovy/NewmanExecuteTest.groovy @@ -68,7 +68,8 @@ class NewmanExecuteTest extends BasePiperTest { newmanGlobals: 'testGlobals' ) // asserts - assertThat(jscr.shell, hasItem('newman run testCollection --environment \'testEnvironment\' --globals \'testGlobals\' --reporters junit,html --reporter-junit-export target/newman/TEST-testCollection.xml --reporter-html-export target/newman/TEST-testCollection.html')) + assertThat(jscr.shell, hasItem('npm install newman newman-reporter-html --global --quiet')) + assertThat(jscr.shell, hasItem('newman run \'testCollection\' --environment \'testEnvironment\' --globals \'testGlobals\' --reporters junit,html --reporter-junit-export \'target/newman/TEST-testCollection.xml\' --reporter-html-export \'target/newman/TEST-testCollection.html\'')) assertThat(jedr.dockerParams.dockerImage, is('node:8-stretch')) assertThat(jlr.log, containsString('[newmanExecute] Found files [testCollection]')) assertJobStatusSuccess() @@ -102,7 +103,7 @@ class NewmanExecuteTest extends BasePiperTest { // asserts assertThat(jedr.dockerParams.dockerImage, is('testImage')) assertThat(gitMap.url, is('testRepo')) - assertThat(jscr.shell, hasItem('newman run testCollection --environment \'testEnvironment\' --globals \'testGlobals\' --reporters junit,html --reporter-junit-export target/newman/TEST-testCollection.xml --reporter-html-export target/newman/TEST-testCollection.html --suppress-exit-code')) + assertThat(jscr.shell, hasItem('newman run \'testCollection\' --environment \'testEnvironment\' --globals \'testGlobals\' --reporters junit,html --reporter-junit-export \'target/newman/TEST-testCollection.xml\' --reporter-html-export \'target/newman/TEST-testCollection.html\' --suppress-exit-code')) assertJobStatusSuccess() } diff --git a/test/groovy/TestsPublishResultsTest.groovy b/test/groovy/TestsPublishResultsTest.groovy index 1955a8fc0..4b5d71092 100644 --- a/test/groovy/TestsPublishResultsTest.groovy +++ b/test/groovy/TestsPublishResultsTest.groovy @@ -75,7 +75,7 @@ class TestsPublishResultsTest extends BasePiperTest { assertTrue('JUnit options are empty', publisherStepOptions.junit != null) // ensure default patterns are set assertEquals('JUnit default pattern not set correct', - '**/target/surefire-reports/*.xml', publisherStepOptions.junit.testResults) + '**/TEST-*.xml', publisherStepOptions.junit.testResults) // ensure nothing else is published assertTrue('JaCoCo options are not empty', publisherStepOptions.jacoco == null) assertTrue('Cobertura options are not empty', publisherStepOptions.cobertura == null) diff --git a/test/groovy/TransportRequestCreateTest.groovy b/test/groovy/TransportRequestCreateTest.groovy index 8a9c0dc52..186c29994 100644 --- a/test/groovy/TransportRequestCreateTest.groovy +++ b/test/groovy/TransportRequestCreateTest.groovy @@ -127,9 +127,9 @@ public class TransportRequestCreateTest extends BasePiperTest { } } - def transportId = jsr.step.transportRequestCreate(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm) + jsr.step.transportRequestCreate(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm) - assert transportId == '001' + assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '001' assert result == [changeId: '001', developmentSystemId: '001', cmEndpoint: 'https://example.org/cm', @@ -166,14 +166,14 @@ public class TransportRequestCreateTest extends BasePiperTest { } } - def transportId = jsr.step.transportRequestCreate(script: nullScript, - transportType: 'W', - targetSystem: 'XYZ', - description: 'desc', - changeManagement: [type: 'CTS'], - cmUtils: cm) + jsr.step.call(script: nullScript, + transportType: 'W', + targetSystem: 'XYZ', + description: 'desc', + changeManagement: [type: 'CTS'], + cmUtils: cm) - assert transportId == '001' + assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '001' assert result == [transportType: 'W', targetSystemId: 'XYZ', description: 'desc', diff --git a/test/groovy/TransportRequestReleaseTest.groovy b/test/groovy/TransportRequestReleaseTest.groovy index 2f740d180..7a41d8f91 100644 --- a/test/groovy/TransportRequestReleaseTest.groovy +++ b/test/groovy/TransportRequestReleaseTest.groovy @@ -108,6 +108,10 @@ public class TransportRequestReleaseTest extends BasePiperTest { @Test public void releaseTransportRequestSuccessTest() { + // Here we test only the case where the transportRequestId is + // provided via parameters. The other cases are tested by + // corresponding tests for StepHelpers#getTransportRequestId(./.) + jlr.expect("[INFO] Closing transport request '002' for change document '001'.") jlr.expect("[INFO] Transport Request '002' has been successfully closed.") diff --git a/test/groovy/TransportRequestUploadFileTest.groovy b/test/groovy/TransportRequestUploadFileTest.groovy index 772ba71fe..ed42e61de 100644 --- a/test/groovy/TransportRequestUploadFileTest.groovy +++ b/test/groovy/TransportRequestUploadFileTest.groovy @@ -194,6 +194,10 @@ public class TransportRequestUploadFileTest extends BasePiperTest { @Test public void uploadFileToTransportRequestSOLMANSuccessTest() { + // Here we test only the case where the transportRequestId is + // provided via parameters. The other cases are tested by + // corresponding tests for StepHelpers#getTransportRequestId(./.) + jlr.expect("[INFO] Uploading file '/path' to transport request '002' of change document '001'.") jlr.expect("[INFO] File '/path' has been successfully uploaded to transport request '002' of change document '001'.") diff --git a/test/groovy/com/sap/piper/cm/StepHelpersTest.groovy b/test/groovy/com/sap/piper/cm/StepHelpersTest.groovy index 7cb6cf904..2df34c4d3 100644 --- a/test/groovy/com/sap/piper/cm/StepHelpersTest.groovy +++ b/test/groovy/com/sap/piper/cm/StepHelpersTest.groovy @@ -20,15 +20,18 @@ class StepHelpersTest extends BasePiperTest { to: 'HEAD', format: '%b' ], - changeDocumentLabel: "ChangeDocument:" + changeDocumentLabel: "ChangeDocument:", + transportRequestLabel: "TransportRequest:", ] ] private Map getChangeDocumentIdReceivedParameters = [:] + private Map getTransportRequestIdReceivedParameters = [:] @Before public void setup() { getChangeDocumentIdReceivedParameters.clear() + getTransportRequestIdReceivedParameters.clear() } JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) @@ -38,6 +41,20 @@ class StepHelpersTest extends BasePiperTest { .around(jlr) private ChangeManagement cm = new ChangeManagement(nullScript) { + + String getTransportRequestId( + String from, + String to, + String label, + String format + ) { + getTransportRequestIdReceivedParameters['from'] = from + getTransportRequestIdReceivedParameters['to'] = to + getTransportRequestIdReceivedParameters['label'] = label + getTransportRequestIdReceivedParameters['format'] = format + return '097' + } + String getChangeDocumentId( String from, String to, @@ -53,6 +70,24 @@ class StepHelpersTest extends BasePiperTest { } @Test + public void transportRequestIdViaCommitHistoryTest() { + + def transportRequestId = StepHelpers.getTransportRequestId(cm, nullScript, params) + + assert transportRequestId == '097' + assert getTransportRequestIdReceivedParameters == + [ + from: 'HEAD~1', + to: 'HEAD', + label: 'TransportRequest:', + format: '%b' + ] + + // We cache the value. Otherwise we have to retrieve it each time from the + // commit history. + assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '097' + } + public void changeDocumentIdViaCommitHistoryTest() { def changeDocumentId = StepHelpers.getChangeDocumentId(cm, nullScript, params) @@ -69,10 +104,60 @@ class StepHelpersTest extends BasePiperTest { // We cache the value. Otherwise we have to retrieve it each time from the // commit history. assert nullScript.commonPipelineEnvironment.getChangeDocumentId() == '001' - } @Test + public void transportRequestIdViaCommonPipelineEnvironmentTest() { + + nullScript.commonPipelineEnvironment.setTransportRequestId('098') + def transportRequestId = StepHelpers.getTransportRequestId(cm, nullScript, params) + + assert transportRequestId == '098' + + // getTransportRequestId gets not called on ChangeManagement util class + // in this case. + assert getTransportRequestIdReceivedParameters == [:] + } + + @Test + public void transportRequestIdViaParametersTest() { + + params << [transportRequestId: '099'] + + def transportRequestId = StepHelpers.getTransportRequestId(cm, nullScript, params) + + assert transportRequestId == '099' + + // In case we get the transport request id via parameters we do not cache it + // Caller knows the transport request id anyway. So the caller can provide it with + // each call. + assert nullScript.commonPipelineEnvironment.getTransportRequestId() == null + + // getTransportRequestId gets not called on ChangeManagement util class + // in this case. + assert getTransportRequestIdReceivedParameters == [:] + } + + @Test + public void transportRequestIdNotProvidedTest() { + + jlr.expect('Cannot retrieve transportRequestId from commit history') + + def cm = new ChangeManagement(nullScript) { + String getTransportRequestId( + String from, + String to, + String label, + String format + ) { + throw new ChangeManagementException('Cannot retrieve transport request id') + } + } + + def transportRequestId = StepHelpers.getTransportRequestId(cm, nullScript, params) + assert transportRequestId == null + } + public void changeDocumentIdViaCommonPipelineEnvironmentTest() { nullScript.commonPipelineEnvironment.setChangeDocumentId('002') @@ -120,8 +205,8 @@ class StepHelpersTest extends BasePiperTest { } } - def transportRequestId = StepHelpers.getChangeDocumentId(cm, nullScript, params) + def changeDocumentId = StepHelpers.getChangeDocumentId(cm, nullScript, params) - assert transportRequestId == null + assert changeDocumentId == null } } diff --git a/vars/artifactSetVersion.groovy b/vars/artifactSetVersion.groovy index 52a9337c5..0c66d816e 100644 --- a/vars/artifactSetVersion.groovy +++ b/vars/artifactSetVersion.groovy @@ -8,7 +8,7 @@ import com.sap.piper.versioning.ArtifactVersioning import groovy.transform.Field import groovy.text.SimpleTemplateEngine -@Field String STEP_NAME = 'artifactSetVersion' +@Field String STEP_NAME = getClass().getName() @Field Map CONFIG_KEY_COMPATIBILITY = [gitSshKeyCredentialsId: 'gitCredentialsId'] @Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS diff --git a/vars/batsExecuteTests.groovy b/vars/batsExecuteTests.groovy index f4f08470f..16a39334d 100644 --- a/vars/batsExecuteTests.groovy +++ b/vars/batsExecuteTests.groovy @@ -6,7 +6,7 @@ import com.sap.piper.Utils import groovy.text.SimpleTemplateEngine import groovy.transform.Field -@Field String STEP_NAME = 'batsExecuteTests' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS @@ -70,7 +70,7 @@ void call(Map parameters = [:]) { } finally { sh "cat 'TEST-${config.testPackage}.tap'" if (config.outputFormat == 'junit') { - dockerExecute(dockerImage: config.dockerImage, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent) { + dockerExecute(script: script, dockerImage: config.dockerImage, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent) { sh "npm install tap-xunit -g" sh "cat 'TEST-${config.testPackage}.tap' | tap-xunit --package='${config.testPackage}' > TEST-${config.testPackage}.xml" } diff --git a/vars/checkChangeInDevelopment.groovy b/vars/checkChangeInDevelopment.groovy index e63b489be..f6521f015 100644 --- a/vars/checkChangeInDevelopment.groovy +++ b/vars/checkChangeInDevelopment.groovy @@ -14,7 +14,7 @@ import com.sap.piper.cm.ChangeManagementException import static com.sap.piper.cm.StepHelpers.getChangeDocumentId import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled -@Field def STEP_NAME = 'checkChangeInDevelopment' +@Field def STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS @@ -97,7 +97,7 @@ void call(parameters = [:]) { new Utils().pushToSWA([step: STEP_NAME, stepParam1: parameters?.script == null], configuration) - def changeId = getChangeDocumentId(cm, this, configuration) + def changeId = getChangeDocumentId(cm, script, configuration) configuration = configHelper.mixin([changeDocumentId: changeId?.trim() ?: null], ['changeDocumentId'] as Set) diff --git a/vars/checksPublishResults.groovy b/vars/checksPublishResults.groovy index dc7b07c82..8ec884252 100644 --- a/vars/checksPublishResults.groovy +++ b/vars/checksPublishResults.groovy @@ -8,7 +8,7 @@ import com.sap.piper.Utils import groovy.transform.Field -@Field def STEP_NAME = 'checksPublishResults' +@Field def STEP_NAME = getClass().getName() @Field Set TOOLS = [ 'aggregation', 'tasks', 'pmd', 'cpd', 'findbugs', 'checkstyle', 'eslint', 'pylint' diff --git a/vars/cloudFoundryDeploy.groovy b/vars/cloudFoundryDeploy.groovy index a206ee6af..b33d25ba8 100644 --- a/vars/cloudFoundryDeploy.groovy +++ b/vars/cloudFoundryDeploy.groovy @@ -6,7 +6,7 @@ import com.sap.piper.CfManifestUtils import groovy.transform.Field -@Field String STEP_NAME = 'cloudFoundryDeploy' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS @@ -15,6 +15,7 @@ import groovy.transform.Field 'deployUser', 'deployTool', 'deployType', + 'keepOldInstance', 'dockerImage', 'dockerWorkspace', 'mtaDeployParameters', @@ -57,7 +58,10 @@ void call(Map parameters = [:]) { echo "[${STEP_NAME}] General parameters: deployTool=${config.deployTool}, deployType=${config.deployType}, cfApiEndpoint=${config.cloudFoundry.apiEndpoint}, cfOrg=${config.cloudFoundry.org}, cfSpace=${config.cloudFoundry.space}, cfCredentialsId=${config.cloudFoundry.credentialsId}, deployUser=${config.deployUser}" - config.stashContent = utils.unstashAll(config.stashContent) + //make sure that all relevant descriptors, are available in workspace + utils.unstashAll(config.stashContent) + //make sure that for further execution whole workspace, e.g. also downloaded artifacts are considered + config.stashContent = [] if (config.deployTool == 'mtaDeployPlugin') { // set default mtar path @@ -65,7 +69,7 @@ void call(Map parameters = [:]) { .addIfEmpty('mtaPath', config.mtaPath?:findMtar()) .use() - dockerExecute(dockerImage: config.dockerImage, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent) { + dockerExecute(script: script, dockerImage: config.dockerImage, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent) { deployMta(config) } return @@ -84,6 +88,7 @@ void call(Map parameters = [:]) { echo "[${STEP_NAME}] CF native deployment (${config.deployType}) with cfAppName=${config.cloudFoundry.appName}, cfManifest=${config.cloudFoundry.manifest}, smokeTestScript=${config.smokeTestScript}" dockerExecute ( + script: script, dockerImage: config.dockerImage, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent, @@ -116,14 +121,16 @@ def deployCfNative (config) { passwordVariable: 'password', usernameVariable: 'username' )]) { - def deployCommand = 'push' + def deployCommand = selectCfDeployCommandForDeployType(config) + if (config.deployType == 'blue-green') { - deployCommand = 'blue-green-deploy' handleLegacyCfManifest(config) } else { config.smokeTest = '' } + def blueGreenDeployOptions = deleteOptionIfRequired(config) + // check if appName is available if (config.cloudFoundry.appName == null || config.cloudFoundry.appName == '') { if (config.deployType == 'blue-green') { @@ -144,11 +151,38 @@ def deployCfNative (config) { export HOME=${config.dockerWorkspace} cf login -u \"${username}\" -p '${password}' -a ${config.cloudFoundry.apiEndpoint} -o \"${config.cloudFoundry.org}\" -s \"${config.cloudFoundry.space}\" cf plugins - cf ${deployCommand} ${config.cloudFoundry.appName?:''} ${config.deployType == 'blue-green'?'--delete-old-apps':''} -f '${config.cloudFoundry.manifest}' ${config.smokeTest}""" + cf ${deployCommand} ${config.cloudFoundry.appName ?: ''} ${blueGreenDeployOptions} -f '${config.cloudFoundry.manifest}' ${config.smokeTest} + ${stopOldAppIfRequired(config)} + """ sh "cf logout" } } +private String selectCfDeployCommandForDeployType(Map config) { + if (config.deployType == 'blue-green') { + return 'blue-green-deploy' + } else { + return 'push' + } +} + +private String deleteOptionIfRequired(Map config) { + boolean deleteOldInstance = !config.keepOldInstance + if (deleteOldInstance && config.deployType == 'blue-green') { + return '--delete-old-apps' + } else { + return '' + } +} + +private String stopOldAppIfRequired(Map config) { + if (config.keepOldInstance && config.deployType == 'blue-green') { + return "cf stop ${config.cloudFoundry.appName}-old" + } else { + return '' + } +} + def deployMta (config) { if (config.mtaExtensionDescriptor == null) config.mtaExtensionDescriptor = '' if (!config.mtaExtensionDescriptor.isEmpty() && !config.mtaExtensionDescriptor.startsWith('-e ')) config.mtaExtensionDescriptor = "-e ${config.mtaExtensionDescriptor}" diff --git a/vars/commonPipelineEnvironment.groovy b/vars/commonPipelineEnvironment.groovy index 7d43536ee..89e34fd74 100644 --- a/vars/commonPipelineEnvironment.groovy +++ b/vars/commonPipelineEnvironment.groovy @@ -30,6 +30,7 @@ class commonPipelineEnvironment implements Serializable { String mtarFilePath + String transportRequestId String changeDocumentId def reset() { @@ -52,6 +53,7 @@ class commonPipelineEnvironment implements Serializable { mtarFilePath = null + transportRequestId = null changeDocumentId = null } diff --git a/vars/dockerExecute.groovy b/vars/dockerExecute.groovy index 4e2c1a559..46e7401bc 100644 --- a/vars/dockerExecute.groovy +++ b/vars/dockerExecute.groovy @@ -9,7 +9,7 @@ import com.sap.piper.k8s.ContainerMap import groovy.transform.Field -@Field def STEP_NAME = 'dockerExecute' +@Field def STEP_NAME = getClass().getName() @Field def PLUGIN_ID_DOCKER_WORKFLOW = 'docker-workflow' @Field Set GENERAL_CONFIG_KEYS = ['jenkinsKubernetes'] diff --git a/vars/dockerExecuteOnKubernetes.groovy b/vars/dockerExecuteOnKubernetes.groovy index ccc1f98c8..e4eb2de89 100644 --- a/vars/dockerExecuteOnKubernetes.groovy +++ b/vars/dockerExecuteOnKubernetes.groovy @@ -7,7 +7,7 @@ import com.sap.piper.k8s.SystemEnv import groovy.transform.Field import hudson.AbortException -@Field def STEP_NAME = 'dockerExecuteOnKubernetes' +@Field def STEP_NAME = getClass().getName() @Field def PLUGIN_ID_KUBERNETES = 'kubernetes' @Field Set GENERAL_CONFIG_KEYS = ['jenkinsKubernetes'] @Field Set PARAMETER_KEYS = [ diff --git a/vars/durationMeasure.groovy b/vars/durationMeasure.groovy index e2bcdc787..2f254dd2c 100644 --- a/vars/durationMeasure.groovy +++ b/vars/durationMeasure.groovy @@ -1,7 +1,7 @@ import static com.sap.piper.Prerequisites.checkScript import groovy.transform.Field -@Field STEP_NAME = 'durationMeasure' +@Field STEP_NAME = getClass().getName() def call(Map parameters = [:], body) { diff --git a/vars/gaugeExecuteTests.groovy b/vars/gaugeExecuteTests.groovy index 2ac46bd4a..e2664ccd5 100644 --- a/vars/gaugeExecuteTests.groovy +++ b/vars/gaugeExecuteTests.groovy @@ -6,7 +6,7 @@ import com.sap.piper.GitUtils import groovy.text.SimpleTemplateEngine import groovy.transform.Field -@Field String STEP_NAME = 'gaugeExecuteTests' +@Field String STEP_NAME = getClass().getName() @Field Set STEP_CONFIG_KEYS = [ 'buildTool', 'dockerEnvVars', diff --git a/vars/githubPublishRelease.groovy b/vars/githubPublishRelease.groovy index d6bcc347b..2ec89bb3c 100644 --- a/vars/githubPublishRelease.groovy +++ b/vars/githubPublishRelease.groovy @@ -5,7 +5,7 @@ import com.sap.piper.ConfigurationHelper import groovy.transform.Field -@Field String STEP_NAME = 'githubPublishRelease' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = ['githubApiUrl', 'githubTokenCredentialsId', 'githubServerUrl'] @Field Set STEP_CONFIG_KEYS = [ 'addClosedIssues', diff --git a/vars/handlePipelineStepErrors.groovy b/vars/handlePipelineStepErrors.groovy index 00bb0ab5d..c304ac7f0 100644 --- a/vars/handlePipelineStepErrors.groovy +++ b/vars/handlePipelineStepErrors.groovy @@ -1,7 +1,7 @@ import groovy.text.SimpleTemplateEngine import groovy.transform.Field -@Field STEP_NAME = 'handlePipelineStepErrors' +@Field STEP_NAME = getClass().getName() void call(Map parameters = [:], body) { def stepParameters = parameters.stepParameters //mandatory diff --git a/vars/healthExecuteCheck.groovy b/vars/healthExecuteCheck.groovy index 723b83cc5..98472d2e2 100644 --- a/vars/healthExecuteCheck.groovy +++ b/vars/healthExecuteCheck.groovy @@ -4,7 +4,7 @@ import com.sap.piper.ConfigurationHelper import com.sap.piper.Utils import groovy.transform.Field -@Field String STEP_NAME = 'healthExecuteCheck' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS diff --git a/vars/influxWriteData.groovy b/vars/influxWriteData.groovy index e1c323f69..e6ed78673 100644 --- a/vars/influxWriteData.groovy +++ b/vars/influxWriteData.groovy @@ -8,7 +8,7 @@ import com.sap.piper.Utils import groovy.transform.Field -@Field def STEP_NAME = 'influxWriteData' +@Field def STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = [] @Field Set STEP_CONFIG_KEYS = [ diff --git a/vars/karmaExecuteTests.groovy b/vars/karmaExecuteTests.groovy index 8dc16752b..e12b00f47 100644 --- a/vars/karmaExecuteTests.groovy +++ b/vars/karmaExecuteTests.groovy @@ -7,7 +7,7 @@ import com.sap.piper.Utils import groovy.text.SimpleTemplateEngine import groovy.transform.Field -@Field String STEP_NAME = 'karmaExecuteTests' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = [ /** port mappings required for containers. This will only take effect inside a Kubernetes pod, format [[containerPort: 1111, hostPort: 1111]] */ 'containerPortMappings', diff --git a/vars/mailSendNotification.groovy b/vars/mailSendNotification.groovy index 5e56c74ae..14fc3333c 100644 --- a/vars/mailSendNotification.groovy +++ b/vars/mailSendNotification.groovy @@ -5,7 +5,7 @@ import com.sap.piper.Utils import groovy.text.SimpleTemplateEngine import groovy.transform.Field -@Field String STEP_NAME = 'mailSendNotification' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = ['gitSshKeyCredentialsId'] @Field Set STEP_CONFIG_KEYS = [ 'projectName', @@ -134,42 +134,47 @@ def getCulpritCommitters(config, currentBuild) { } def getCulprits(config, branch, numberOfCommits) { - if (branch?.startsWith('PR-')) { - //special GitHub Pull Request handling - deleteDir() - sshagent( - credentials: [config.gitSshKeyCredentialsId], - ignoreMissing: true - ) { - def pullRequestID = branch.replaceAll('PR-', '') - def localBranchName = "pr" + pullRequestID; - sh """git init -git fetch ${config.gitUrl} pull/${pullRequestID}/head:${localBranchName} > /dev/null 2>&1 -git checkout -f ${localBranchName} > /dev/null 2>&1 -""" - } - } else { - //standard git/GitHub handling - if (config.gitCommitId) { + try { + if (branch?.startsWith('PR-')) { + //special GitHub Pull Request handling deleteDir() sshagent( credentials: [config.gitSshKeyCredentialsId], ignoreMissing: true ) { - sh """git clone ${config.gitUrl} . -git checkout ${config.gitCommitId} > /dev/null 2>&1""" + def pullRequestID = branch.replaceAll('PR-', '') + def localBranchName = "pr" + pullRequestID; + sh """git init + git fetch ${config.gitUrl} pull/${pullRequestID}/head:${localBranchName} > /dev/null 2>&1 + git checkout -f ${localBranchName} > /dev/null 2>&1 + """ } } else { - def retCode = sh(returnStatus: true, script: 'git log > /dev/null 2>&1') - if (retCode != 0) { - echo "[${STEP_NAME}] No git context available to retrieve culprits" - return '' + //standard git/GitHub handling + if (config.gitCommitId) { + deleteDir() + sshagent( + credentials: [config.gitSshKeyCredentialsId], + ignoreMissing: true + ) { + sh """git clone ${config.gitUrl} . + git checkout ${config.gitCommitId} > /dev/null 2>&1""" + } + } else { + def retCode = sh(returnStatus: true, script: 'git log > /dev/null 2>&1') + if (retCode != 0) { + echo "[${STEP_NAME}] No git context available to retrieve culprits" + return '' + } } } - } - def recipients = sh(returnStdout: true, script: "git log -${numberOfCommits} --pretty=format:'%ae %ce'") - return getDistinctRecipients(recipients) + def recipients = sh(returnStdout: true, script: "git log -${numberOfCommits} --pretty=format:'%ae %ce'") + return getDistinctRecipients(recipients) + } catch(err) { + echo "[${STEP_NAME}] Culprit retrieval from git failed with '${err.getMessage()}'. Please make sure to configure gitSshKeyCredentialsId. So far, only fixed list of recipients is used." + return '' + } } def getDistinctRecipients(recipients){ diff --git a/vars/mavenExecute.groovy b/vars/mavenExecute.groovy index 704bdbc8c..c91137cc4 100644 --- a/vars/mavenExecute.groovy +++ b/vars/mavenExecute.groovy @@ -5,7 +5,7 @@ import com.sap.piper.Utils import groovy.transform.Field -@Field def STEP_NAME = 'mavenExecute' +@Field def STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = [] @Field Set STEP_CONFIG_KEYS = [ diff --git a/vars/mtaBuild.groovy b/vars/mtaBuild.groovy index c0161b83b..d355bd274 100644 --- a/vars/mtaBuild.groovy +++ b/vars/mtaBuild.groovy @@ -8,7 +8,7 @@ import com.sap.piper.tools.ToolDescriptor import groovy.transform.Field -@Field def STEP_NAME = 'mtaBuild' +@Field def STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = [] @Field Set STEP_CONFIG_KEYS = [ @@ -82,8 +82,7 @@ void call(Map parameters = [:]) { $mtaCall """ - def mtarFilePath = "${mtarFileName}" - script?.commonPipelineEnvironment?.setMtarFilePath(mtarFilePath) + script?.commonPipelineEnvironment?.setMtarFilePath(mtarFileName) } } } diff --git a/vars/neoDeploy.groovy b/vars/neoDeploy.groovy index bddb754be..66d4bf134 100644 --- a/vars/neoDeploy.groovy +++ b/vars/neoDeploy.groovy @@ -7,7 +7,7 @@ import com.sap.piper.tools.ToolDescriptor import groovy.transform.Field -@Field String STEP_NAME = 'neoDeploy' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = [] @Field Set STEP_CONFIG_KEYS = [ 'account', @@ -36,7 +36,7 @@ void call(parameters = [:]) { def script = checkScript(this, parameters) ?: this - def utils = new Utils() + def utils = parameters.utils ?: new Utils() prepareDefaultValues script: script @@ -72,6 +72,23 @@ void call(parameters = [:]) { echo "[WARNING][${STEP_NAME}] Deprecated parameter 'neoCredentialsId' from old configuration framework is used. This will not work anymore in future versions." parameters.put('neoCredentialsId', credId) } + + if(! stepCompatibilityConfiguration.isEmpty()) { + echo "[WARNING][$STEP_NAME] You are using a deprecated configuration framework. This will be removed in " + + 'futureVersions.\nAdd snippet below to \'./pipeline/config.yml\' and remove ' + + 'file \'.pipeline/configuration.properties\'.\n' + + """|steps: + | neoDeploy: + | host: ${stepCompatibilityConfiguration.get('host', '')} + | account: ${stepCompatibilityConfiguration.get('account', '')} + """.stripMargin() + + if(Boolean.getBoolean('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy')) { + script.currentBuild.setResult('UNSTABLE') + echo "[WARNING][$STEP_NAME] Build has been set to unstable since old config framework is used." + } + } + // Backward compatibility end // load default & individual configuration @@ -89,7 +106,8 @@ void call(parameters = [:]) { step: STEP_NAME, stepParam1: configuration.deployMode == 'mta'?'mta':'war', // ['mta', 'warParams', 'warPropertiesFile'] stepParam2: configuration.warAction == 'rolling-update'?'blue-green':'standard', // ['deploy', 'deploy-mta', 'rolling-update'] - stepParam3: parameters?.script == null + stepParam3: parameters?.script == null, + stepParam4: ! stepCompatibilityConfiguration.isEmpty(), ], configuration) def archivePath = configuration.archivePath diff --git a/vars/newmanExecute.groovy b/vars/newmanExecute.groovy index ab43895db..cd2e2019b 100644 --- a/vars/newmanExecute.groovy +++ b/vars/newmanExecute.groovy @@ -6,7 +6,7 @@ import com.sap.piper.Utils import groovy.text.SimpleTemplateEngine import groovy.transform.Field -@Field String STEP_NAME = 'newmanExecute' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS @@ -18,6 +18,7 @@ import groovy.transform.Field 'newmanCollection', 'newmanEnvironment', 'newmanGlobals', + 'newmanInstallCommand', 'newmanRunCommand', 'stashContent', 'testRepository' @@ -56,10 +57,11 @@ void call(Map parameters = [:]) { } dockerExecute( + script: script, dockerImage: config.dockerImage, stashContent: config.stashContent ) { - sh 'npm install newman --global --quiet' + sh "${config.newmanInstallCommand}" for(String collection : collectionList){ def collectionDisplayName = collection.toString().replace(File.separatorChar,(char)'_').tokenize('.').first() // resolve templates diff --git a/vars/pipelineExecute.groovy b/vars/pipelineExecute.groovy index 2607c5c8d..85f95aab8 100644 --- a/vars/pipelineExecute.groovy +++ b/vars/pipelineExecute.groovy @@ -3,7 +3,7 @@ import com.sap.piper.Utils import groovy.transform.Field -@Field STEP_NAME = 'pipelineExecute' +@Field STEP_NAME = getClass().getName() /** diff --git a/vars/pipelineRestartSteps.groovy b/vars/pipelineRestartSteps.groovy index b90d2c110..d94a34415 100644 --- a/vars/pipelineRestartSteps.groovy +++ b/vars/pipelineRestartSteps.groovy @@ -4,7 +4,7 @@ import com.sap.piper.JenkinsUtils import com.sap.piper.ConfigurationHelper import groovy.transform.Field -@Field String STEP_NAME = 'pipelineRestartSteps' +@Field String STEP_NAME = getClass().getName() @Field Set STEP_CONFIG_KEYS = [ 'sendMail', 'timeoutInSeconds' diff --git a/vars/pipelineStashFiles.groovy b/vars/pipelineStashFiles.groovy index cb58e7e91..286562293 100644 --- a/vars/pipelineStashFiles.groovy +++ b/vars/pipelineStashFiles.groovy @@ -1,6 +1,6 @@ import groovy.transform.Field -@Field STEP_NAME = 'pipelineStashFiles' +@Field STEP_NAME = getClass().getName() void call(Map parameters = [:], body) { handlePipelineStepErrors (stepName: 'pipelineStashFiles', stepParameters: parameters) { diff --git a/vars/pipelineStashFilesAfterBuild.groovy b/vars/pipelineStashFilesAfterBuild.groovy index 0e3ad303b..7ca2a56ad 100644 --- a/vars/pipelineStashFilesAfterBuild.groovy +++ b/vars/pipelineStashFilesAfterBuild.groovy @@ -4,7 +4,7 @@ import com.sap.piper.Utils import com.sap.piper.ConfigurationHelper import groovy.transform.Field -@Field String STEP_NAME = 'pipelineStashFilesAfterBuild' +@Field String STEP_NAME = getClass().getName() @Field Set STEP_CONFIG_KEYS = ['runCheckmarx', 'stashIncludes', 'stashExcludes'] @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS @@ -48,14 +48,14 @@ void call(Map parameters = [:]) { utils.stashWithMessage( 'classFiles', - '[${STEP_NAME}] Failed to stash class files.', + "[${STEP_NAME}] Failed to stash class files.", config.stashIncludes.classFiles, config.stashExcludes.classFiles ) utils.stashWithMessage( 'sonar', - '[${STEP_NAME}] Failed to stash sonar files.', + "[${STEP_NAME}] Failed to stash sonar files.", config.stashIncludes.sonar, config.stashExcludes.sonar ) diff --git a/vars/pipelineStashFilesBeforeBuild.groovy b/vars/pipelineStashFilesBeforeBuild.groovy index 161c3f892..86657feaf 100644 --- a/vars/pipelineStashFilesBeforeBuild.groovy +++ b/vars/pipelineStashFilesBeforeBuild.groovy @@ -4,7 +4,7 @@ import com.sap.piper.Utils import com.sap.piper.ConfigurationHelper import groovy.transform.Field -@Field String STEP_NAME = 'pipelineStashFilesBeforeBuild' +@Field String STEP_NAME = getClass().getName() @Field Set STEP_CONFIG_KEYS = ['runOpaTests', 'stashIncludes', 'stashExcludes'] @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS @@ -48,7 +48,7 @@ void call(Map parameters = [:]) { //store deployment descriptor files depending on technology, e.g. *.mtaext.yml utils.stashWithMessage( 'deployDescriptor', - '[${STEP_NAME}] no deployment descriptor files provided: ', + "[${STEP_NAME}] no deployment descriptor files provided: ", config.stashIncludes.deployDescriptor, config.stashExcludes.deployDescriptor ) @@ -58,34 +58,34 @@ void call(Map parameters = [:]) { sh "chmod -R u+w gitmetadata" utils.stashWithMessage( 'git', - '[${STEP_NAME}] no git repo files detected: ', + "[${STEP_NAME}] no git repo files detected: ", config.stashIncludes.git, config.stashExcludes.git ) //store nsp & retire exclusion file for future use utils.stashWithMessage( 'opensourceConfiguration', - '[${STEP_NAME}] no opensourceConfiguration files provided: ', + "[${STEP_NAME}] no opensourceConfiguration files provided: ", config.stashIncludes.get('opensourceConfiguration'), config.stashExcludes.get('opensourceConfiguration') ) //store pipeline configuration including additional groovy test scripts for future use utils.stashWithMessage( 'pipelineConfigAndTests', - '[${STEP_NAME}] no pipeline configuration and test files found: ', + "[${STEP_NAME}] no pipeline configuration and test files found: ", config.stashIncludes.pipelineConfigAndTests, config.stashExcludes.pipelineConfigAndTests ) utils.stashWithMessage( 'securityDescriptor', - '[${STEP_NAME}] no security descriptor found: ', + "[${STEP_NAME}] no security descriptor found: ", config.stashIncludes.securityDescriptor, config.stashExcludes.securityDescriptor ) //store files required for tests, e.g. Gauge, SUT, ... utils.stashWithMessage( 'tests', - '[${STEP_NAME}] no files for tests provided: ', + "[${STEP_NAME}] no files for tests provided: ", config.stashIncludes.tests, config.stashExcludes.tests ) diff --git a/vars/prepareDefaultValues.groovy b/vars/prepareDefaultValues.groovy index 9c049065c..c1e80d323 100644 --- a/vars/prepareDefaultValues.groovy +++ b/vars/prepareDefaultValues.groovy @@ -3,7 +3,7 @@ import com.sap.piper.MapUtils import groovy.transform.Field -@Field STEP_NAME = 'prepareDefaultValues' +@Field STEP_NAME = getClass().getName() void call(Map parameters = [:]) { handlePipelineStepErrors (stepName: 'prepareDefaultValues', stepParameters: parameters) { diff --git a/vars/seleniumExecuteTests.groovy b/vars/seleniumExecuteTests.groovy index 62a637e71..93823db2d 100644 --- a/vars/seleniumExecuteTests.groovy +++ b/vars/seleniumExecuteTests.groovy @@ -7,7 +7,7 @@ import com.sap.piper.k8s.ContainerMap import groovy.transform.Field import groovy.text.SimpleTemplateEngine -@Field String STEP_NAME = 'seleniumExecuteTests' +@Field String STEP_NAME = getClass().getName() @Field GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS diff --git a/vars/setupCommonPipelineEnvironment.groovy b/vars/setupCommonPipelineEnvironment.groovy index c9298e14c..ea6d1f704 100644 --- a/vars/setupCommonPipelineEnvironment.groovy +++ b/vars/setupCommonPipelineEnvironment.groovy @@ -4,7 +4,7 @@ import com.sap.piper.ConfigurationHelper import com.sap.piper.Utils import groovy.transform.Field -@Field String STEP_NAME = 'setupCommonPipelineEnvironment' +@Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = ['collectTelemetryData'] void call(Map parameters = [:]) { diff --git a/vars/snykExecute.groovy b/vars/snykExecute.groovy index 909bb060a..f555f04b2 100644 --- a/vars/snykExecute.groovy +++ b/vars/snykExecute.groovy @@ -6,7 +6,7 @@ import com.sap.piper.mta.MtaMultiplexer import groovy.transform.Field -@Field def STEP_NAME = 'snykExecute' +@Field def STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = ['snykCredentialsId'] @Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([ @@ -62,6 +62,7 @@ void call(Map parameters = [:]) { variable: 'token' )]) { dockerExecute( + script: script, dockerImage: config.dockerImage, stashContent: config.stashContent, dockerEnvVars: ['SNYK_TOKEN': token] diff --git a/vars/testsPublishResults.groovy b/vars/testsPublishResults.groovy index 03875bb96..881aa9b05 100644 --- a/vars/testsPublishResults.groovy +++ b/vars/testsPublishResults.groovy @@ -11,7 +11,7 @@ import groovy.transform.Field 'junit','jacoco','cobertura','jmeter' ] -@Field def STEP_NAME = 'testsPublishResults' +@Field def STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = TOOLS @Field Set STEP_CONFIG_KEYS = TOOLS @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS diff --git a/vars/toolValidate.groovy b/vars/toolValidate.groovy index 2813764d7..7168809d6 100644 --- a/vars/toolValidate.groovy +++ b/vars/toolValidate.groovy @@ -8,7 +8,7 @@ import groovy.transform.Field import hudson.AbortException -@Field STEP_NAME = 'toolValidate' +@Field STEP_NAME = getClass().getName() void call(Map parameters = [:]) { diff --git a/vars/transportRequestCreate.groovy b/vars/transportRequestCreate.groovy index 1fec7d580..91b27e5bb 100644 --- a/vars/transportRequestCreate.groovy +++ b/vars/transportRequestCreate.groovy @@ -13,7 +13,7 @@ import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrati import static com.sap.piper.cm.StepHelpers.getChangeDocumentId import hudson.AbortException -@Field def STEP_NAME = 'transportRequestCreate' +@Field def STEP_NAME = getClass().getName() @Field GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS @@ -27,7 +27,7 @@ import hudson.AbortException @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus(['changeDocumentId']) -def call(parameters = [:]) { +void call(parameters = [:]) { def transportRequestId @@ -68,7 +68,7 @@ def call(parameters = [:]) { if(backendType == BackendType.SOLMAN) { - changeDocumentId = getChangeDocumentId(cm, this, configuration) + changeDocumentId = getChangeDocumentId(cm, script, configuration) configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set) .withMandatoryProperty('developmentSystemId') @@ -110,7 +110,6 @@ def call(parameters = [:]) { echo "[INFO] Transport Request '$transportRequestId' has been successfully created." + script.commonPipelineEnvironment.setTransportRequestId(transportRequestId) } - - return transportRequestId } diff --git a/vars/transportRequestRelease.groovy b/vars/transportRequestRelease.groovy index 9c28d7dcd..938a3c6f0 100644 --- a/vars/transportRequestRelease.groovy +++ b/vars/transportRequestRelease.groovy @@ -14,7 +14,7 @@ import static com.sap.piper.cm.StepHelpers.getTransportRequestId import static com.sap.piper.cm.StepHelpers.getChangeDocumentId import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled -@Field def STEP_NAME = 'transportRequestRelease' +@Field def STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS @@ -62,11 +62,11 @@ void call(parameters = [:]) { stepParam1: parameters?.script == null], configuration) def changeDocumentId = null - def transportRequestId = getTransportRequestId(cm, this, configuration) + def transportRequestId = getTransportRequestId(cm, script, configuration) if(backendType == BackendType.SOLMAN) { - changeDocumentId = getChangeDocumentId(cm, this, configuration) + changeDocumentId = getChangeDocumentId(cm, script, configuration) configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set) .withMandatoryProperty('changeDocumentId', diff --git a/vars/transportRequestUploadFile.groovy b/vars/transportRequestUploadFile.groovy index 420b59592..10a6a7d71 100644 --- a/vars/transportRequestUploadFile.groovy +++ b/vars/transportRequestUploadFile.groovy @@ -14,7 +14,7 @@ import static com.sap.piper.cm.StepHelpers.getTransportRequestId import static com.sap.piper.cm.StepHelpers.getChangeDocumentId import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled -@Field def STEP_NAME = 'transportRequestUploadFile' +@Field def STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = [ 'changeManagement' @@ -68,10 +68,10 @@ void call(parameters = [:]) { def changeDocumentId = null if(backendType == BackendType.SOLMAN) { - changeDocumentId = getChangeDocumentId(cm, this, configuration) + changeDocumentId = getChangeDocumentId(cm, script, configuration) } - def transportRequestId = getTransportRequestId(cm, this, configuration) + def transportRequestId = getTransportRequestId(cm, script, configuration) configHelper .mixin([changeDocumentId: changeDocumentId?.trim() ?: null,