1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-03 15:02:35 +02:00

Merge pull request #305 from marcusholl/pr/scriptAsMandatoryParameter

Ensure script is mandatory parameter
This commit is contained in:
Marcus Holl 2018-11-05 13:45:08 +01:00 committed by GitHub
commit 1835f4d7bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 369 additions and 107 deletions

View File

@ -21,7 +21,7 @@ none
| parameter | mandatory | default | possible values | | parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------| | ----------|-----------|---------|-----------------|
| script | no | empty `commonPipelineEnvironment` | | | script | yes | | |
| artifactType | no | | 'appContainer' | | artifactType | no | | 'appContainer' |
| buildTool | no | maven | docker, dlang, golang, maven, mta, npm, pip, sbt | | buildTool | no | maven | docker, dlang, golang, maven, mta, npm, pip, sbt |
| commitVersion | no | `true` | `true`, `false` | | commitVersion | no | `true` | `true`, `false` |

View File

@ -12,7 +12,7 @@ You need to have a Bats test file. By default you would put this into directory
| parameter | mandatory | default | possible values | | parameter | mandatory | default | possible values |
|-----------|-----------|---------|-----------------| |-----------|-----------|---------|-----------------|
| script | no | empty `globalPipelineEnvironment` | | | script | yes | | |
| dockerImage | no | `node:8-stretch` | | | dockerImage | no | `node:8-stretch` | |
| dockerWorkspace | no |`/home/node`| | | dockerWorkspace | no |`/home/node`| |
| envVars | no | `[:]` | | | envVars | no | `[:]` | |

View File

@ -16,6 +16,7 @@ This step can publish static check results from various sources.
## Parameters ## Parameters
| parameter | mandatory | default | possible values | | parameter | mandatory | default | possible values |
| ---------------|-----------|-----------------------------------|--------------------| | ---------------|-----------|-----------------------------------|--------------------|
| script | yes | | |
| aggregation | no | `true` | see below | | aggregation | no | `true` | see below |
| tasks | no | `false` | see below | | tasks | no | `false` | see below |
| pmd | no | `false` | see below | | pmd | no | `false` | see below |

View File

@ -26,7 +26,7 @@ Deployment can be done
| parameter | mandatory | default | possible values | | parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------| | ----------|-----------|---------|-----------------|
| script | no | empty `commonPipelineEnvironment` | | | script | yes | | |
| cloudFoundry | yes | | | | cloudFoundry | yes | | |
| deployTool | no | cf_native | cf_native, mtaDeployPlugin | | deployTool | no | cf_native | cf_native, mtaDeployPlugin |
| deployType | no | standard | standard, blue-green | | deployType | no | standard | standard, blue-green |

View File

@ -18,7 +18,7 @@ none
| parameter | mandatory | default | possible values | | parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------| | ----------|-----------|---------|-----------------|
| script | no | empty `globalPipelineEnvironment` | | | script | yes | | |
| measurementName | no | test_duration | | | measurementName | no | test_duration | |
Details: Details:

View File

@ -84,7 +84,7 @@ influxDBServer=jenkins
| parameter | mandatory | default | possible values | | parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------| | ----------|-----------|---------|-----------------|
| script | no | empty `commonPipelineEnvironment` | | | script | yes | | |
| artifactVersion | yes | commonPipelineEnvironment.getArtifactVersion() | | | artifactVersion | yes | commonPipelineEnvironment.getArtifactVersion() | |
| influxServer | no | `jenkins` | | | influxServer | no | `jenkins` | |
| influxPrefix | no | `null` | | | influxPrefix | no | `null` | |

View File

@ -8,6 +8,7 @@ Executes a maven command inside a Docker container.
| parameter | mandatory | default | example values | | parameter | mandatory | default | example values |
| -------------------------------|-----------|-------------------|----------------------------| | -------------------------------|-----------|-------------------|----------------------------|
| `script` | yes | | |
| `dockerImage` | no | 'maven:3.5-jdk-7' | | | `dockerImage` | no | 'maven:3.5-jdk-7' | |
| `globalSettingsFile` | no | | 'local_folder/settings.xml'| | `globalSettingsFile` | no | | 'local_folder/settings.xml'|
| `projectSettingsFile` | no | | | | `projectSettingsFile` | no | | |
@ -18,6 +19,10 @@ Executes a maven command inside a Docker container.
| `defines` | no | | '-Dmaven.tests.skip=true' | | `defines` | no | | '-Dmaven.tests.skip=true' |
| `logSuccessfulMavenTransfers` | no | `false` | 'true' | | `logSuccessfulMavenTransfers` | no | `false` | 'true' |
* `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 for retrieving, for example,
configuration parameters.
* `dockerImage` Name of the docker image that should be used. * `dockerImage` Name of the docker image that should be used.
* `globalSettingsFile` Path or url to the mvn settings file that should be used as global settings file. * `globalSettingsFile` Path or url to the mvn settings file that should be used as global settings file.
* `projectSettingsFile` Path or url to the mvn settings file that should be used as project settings file. * `projectSettingsFile` Path or url to the mvn settings file that should be used as project settings file.

View File

@ -10,7 +10,7 @@ none
| parameter | mandatory | default | possible values | | parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------| | ----------|-----------|---------|-----------------|
| script | no | empty `commonPipelineEnvironment` | | | script | yes | | |
| runCheckmarx | no | false | | | runCheckmarx | no | false | |
| runOpaTests | no | false | | | runOpaTests | no | false | |
| stashIncludes | no | see details | | | stashIncludes | no | see details | |

View File

@ -31,11 +31,17 @@ Available parameters:
| parameter | mandatory | default | possible values | | parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------| | ----------|-----------|---------|-----------------|
| script | yes | | |
| junit | no | `false` | true, false | | junit | no | `false` | true, false |
| jacoco | no | `false` | true, false | | jacoco | no | `false` | true, false |
| cobertura | no | `false` | true, false | | cobertura | no | `false` | true, false |
| jmeter | no | `false` | true, false | | jmeter | no | `false` | true, false |
* `script` - 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`.
This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md)
for retrieving, for example, configuration parameters.
* `junit` - Publishes test results files in JUnit format with the [JUnit Plugin](https://plugins.jenkins.io/junit). * `junit` - Publishes test results files in JUnit format with the [JUnit Plugin](https://plugins.jenkins.io/junit).
* `jacoco` - Publishes code coverage with the [JaCoCo plugin](https://plugins.jenkins.io/jacoco) . * `jacoco` - Publishes code coverage with the [JaCoCo plugin](https://plugins.jenkins.io/jacoco) .
* `cobertura` - Publishes code coverage with the [Cobertura plugin](https://plugins.jenkins.io/cobertura). * `cobertura` - Publishes code coverage with the [Cobertura plugin](https://plugins.jenkins.io/cobertura).

View File

@ -0,0 +1,22 @@
package com.sap.piper
import static java.lang.Boolean.getBoolean
static checkScript(def step, Map params) {
def script = params?.script
if(script == null) {
if(getBoolean('com.sap.piper.featureFlag.failOnMissingScript')) {
step.error("[ERROR][${step.STEP_NAME}] No reference to surrounding script provided with key 'script', e.g. 'script: this'.")
}
step.currentBuild.setResult('UNSTABLE')
step.echo "[WARNING][${step.STEP_NAME}] No reference to surrounding script provided with key 'script', e.g. 'script: this'. " +
"Build status has been set to 'UNSTABLE'. In future versions of piper-lib the build will fail."
}
return script
}

View File

@ -8,6 +8,7 @@ import org.junit.rules.RuleChain
import com.sap.piper.GitUtils import com.sap.piper.GitUtils
import hudson.AbortException
import util.BasePiperTest import util.BasePiperTest
import util.JenkinsDockerExecuteRule import util.JenkinsDockerExecuteRule
import util.JenkinsEnvironmentRule import util.JenkinsEnvironmentRule
@ -109,14 +110,6 @@ class ArtifactSetVersionTest extends BasePiperTest {
assertThat(jscr.shell, not(hasItem(containsString('commit')))) assertThat(jscr.shell, not(hasItem(containsString('commit'))))
} }
@Test
void testVersioningWithoutScript() {
jsr.step.artifactSetVersion(juStabGitUtils: gitUtils, buildTool: 'maven', commitVersion: false)
assertEquals('1.2.3-20180101010203_testCommitId', jer.env.getArtifactVersion())
assertThat(jscr.shell, hasItem("mvn --file 'pom.xml' --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn versions:set -DnewVersion=1.2.3-20180101010203_testCommitId -DgenerateBackupPoms=false"))
}
@Test @Test
void testVersioningCustomGitUserAndEMail() { void testVersioningCustomGitUserAndEMail() {
jsr.step.artifactSetVersion(script: jsr.step, juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl', gitUserEMail: 'test@test.com', gitUserName: 'test') jsr.step.artifactSetVersion(script: jsr.step, juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl', gitUserEMail: 'test@test.com', gitUserName: 'test')

View File

@ -45,11 +45,11 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
ChangeManagement cm = getChangeManagementUtils(true) ChangeManagement cm = getChangeManagementUtils(true)
jsr.step.checkChangeInDevelopment( jsr.step.checkChangeInDevelopment(
script: nullScript, script: nullScript,
cmUtils: cm, cmUtils: cm,
changeManagement: [ changeManagement: [
type: 'SOLMAN', type: 'SOLMAN',
endpoint: 'https://example.org/cm'], endpoint: 'https://example.org/cm'],
failIfStatusIsNotInDevelopment: true) failIfStatusIsNotInDevelopment: true)
assert cmUtilReceivedParams == [ assert cmUtilReceivedParams == [
changeId: '001', changeId: '001',
@ -80,7 +80,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
ChangeManagement cm = getChangeManagementUtils(false) ChangeManagement cm = getChangeManagementUtils(false)
boolean inDevelopment = jsr.step.checkChangeInDevelopment( boolean inDevelopment = jsr.step.checkChangeInDevelopment(
script: nullScript, script: nullScript,
cmUtils: cm, cmUtils: cm,
changeManagement: [endpoint: 'https://example.org/cm'], changeManagement: [endpoint: 'https://example.org/cm'],
failIfStatusIsNotInDevelopment: false) failIfStatusIsNotInDevelopment: false)

View File

@ -43,7 +43,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishWithDefaultSettings() throws Exception { void testPublishWithDefaultSettings() throws Exception {
jsr.step.call() jsr.step.call(script: nullScript)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
// ensure nothing else is published // ensure nothing else is published
@ -56,7 +56,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishForJavaWithDefaultSettings() throws Exception { void testPublishForJavaWithDefaultSettings() throws Exception {
jsr.step.call(pmd: true, cpd: true, findbugs: true, checkstyle: true) jsr.step.call(script: nullScript, pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null) assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -74,7 +74,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishForJavaScriptWithDefaultSettings() throws Exception { void testPublishForJavaScriptWithDefaultSettings() throws Exception {
jsr.step.call(eslint: true) jsr.step.call(script: nullScript, eslint: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null) assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
@ -92,7 +92,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishForPythonWithDefaultSettings() throws Exception { void testPublishForPythonWithDefaultSettings() throws Exception {
jsr.step.call(pylint: true) jsr.step.call(script: nullScript, pylint: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null) assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
@ -111,7 +111,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishNothing() throws Exception { void testPublishNothing() throws Exception {
jsr.step.call(aggregation: false) jsr.step.call(script: nullScript, aggregation: false)
// ensure nothing is published // ensure nothing is published
assertTrue("AnalysisPublisher options not empty", publisherStepOptions['AnalysisPublisher'] == null) assertTrue("AnalysisPublisher options not empty", publisherStepOptions['AnalysisPublisher'] == null)
@ -124,7 +124,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishNothingExplicitFalse() throws Exception { void testPublishNothingExplicitFalse() throws Exception {
jsr.step.call(pmd: false) jsr.step.call(script: nullScript, pmd: false)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
// ensure nothing else is published // ensure nothing else is published
@ -137,7 +137,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishNothingImplicitTrue() throws Exception { void testPublishNothingImplicitTrue() throws Exception {
jsr.step.call(pmd: [:]) jsr.step.call(script: nullScript, pmd: [:])
// ensure pmd is not published // ensure pmd is not published
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null) assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -145,7 +145,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishNothingExplicitActiveFalse() throws Exception { void testPublishNothingExplicitActiveFalse() throws Exception {
jsr.step.call(pmd: [active: false]) jsr.step.call(script: nullScript, pmd: [active: false])
// ensure pmd is not published // ensure pmd is not published
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null) assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
@ -169,7 +169,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishWithCustomPattern() throws Exception { void testPublishWithCustomPattern() throws Exception {
jsr.step.call(eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml']) jsr.step.call(script: nullScript, eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml'])
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null) assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -186,7 +186,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishWithArchive() throws Exception { void testPublishWithArchive() throws Exception {
jsr.step.call(archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true) jsr.step.call(script: nullScript, archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 5) assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 5)
assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml')) assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
@ -198,7 +198,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishWithPartialArchive() throws Exception { void testPublishWithPartialArchive() throws Exception {
jsr.step.call(archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true) jsr.step.call(script: nullScript, archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 4) assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 4)
assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml')) assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
@ -211,7 +211,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishWithDefaultThresholds() throws Exception { void testPublishWithDefaultThresholds() throws Exception {
jsr.step.call(pmd: true) jsr.step.call(script: nullScript, pmd: true)
assertTrue("AnalysisPublisher options not set", assertTrue("AnalysisPublisher options not set",
publisherStepOptions['AnalysisPublisher'] != null) publisherStepOptions['AnalysisPublisher'] != null)
@ -245,7 +245,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
@Test @Test
void testPublishWithThresholds() throws Exception { void testPublishWithThresholds() throws Exception {
jsr.step.call(aggregation: [thresholds: [fail: [high: '10']]], pmd: true) jsr.step.call(script: nullScript, aggregation: [thresholds: [fail: [high: '10']]], pmd: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null) assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)

View File

@ -1,20 +1,26 @@
import static java.util.stream.Collectors.toList import static java.util.stream.Collectors.toList
import static org.hamcrest.Matchers.empty import static org.hamcrest.Matchers.empty
import static org.hamcrest.Matchers.equalTo
import static org.hamcrest.Matchers.is import static org.hamcrest.Matchers.is
import static org.junit.Assert.assertThat import static org.junit.Assert.assertThat
import static org.junit.Assert.fail import static org.junit.Assert.fail
import java.lang.reflect.Field
import java.io.File; import java.io.File;
import java.util.stream.Collectors
import java.lang.reflect.Field
import org.codehaus.groovy.runtime.metaclass.MethodSelectionException
import org.hamcrest.Matchers
import org.junit.Assert import org.junit.Assert
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain import org.junit.rules.RuleChain
import groovy.io.FileType import groovy.io.FileType
import hudson.AbortException
import util.BasePiperTest import util.BasePiperTest
import util.JenkinsStepRule
import util.Rules import util.Rules
/* /*
@ -25,6 +31,74 @@ public class CommonStepsTest extends BasePiperTest{
@Rule @Rule
public RuleChain ruleChain = Rules.getCommonRules(this) public RuleChain ruleChain = Rules.getCommonRules(this)
/*
* With that test we ensure the very first action inside a method body of a call method
* for a not white listed step is the check for the script handed over properly.
* Actually we assert for the exception type (AbortException) and for the exception message.
* In case a new step is added this step will fail. It is the duty of the author of the
* step to either follow the pattern of checking the script first or to add the step
* to the white list.
*/
@Test
public void scriptReferenceNotHandedOverTest() {
// all steps not adopting the usual pattern of working with the script.
def whitelistScriptReference = [
'commonPipelineEnvironment',
'handlePipelineStepErrors',
'pipelineExecute',
'prepareDefaultValues',
'setupCommonPipelineEnvironment',
'toolValidate',
]
List steps = getSteps().stream()
.filter {! whitelistScriptReference.contains(it)}
.forEach {checkReference(it)}
}
private void checkReference(step) {
try {
def script = loadScript("${step}.groovy")
try {
System.setProperty('com.sap.piper.featureFlag.failOnMissingScript', 'true')
try {
script.call([:])
} catch(AbortException | MissingMethodException e) {
throw e
} catch(Exception e) {
fail "Unexpected exception ${e.getClass().getName()} caught from step '${step}': ${e.getMessage()}"
}
fail("Expected AbortException not raised by step '${step}'")
} catch(MissingMethodException e) {
// can be improved: exception handling as some kind of control flow.
// we can also check for the methods and call the appropriate one.
try {
script.call([:]) {}
} catch(AbortException e1) {
throw e1
} catch(Exception e1) {
fail "Unexpected exception ${e1.getClass().getName()} caught from step '${step}': ${e1.getMessage()}"
}
fail("Expected AbortException not raised by step '${step}'")
}
} catch(AbortException e) {
assertThat("Step ''${step} does not fail with expected error message in case mandatory parameter 'script' is not provided.",
e.getMessage() ==~ /.*\[ERROR\]\[.*\] No reference to surrounding script provided with key 'script', e.g. 'script: this'./,
is(equalTo(true)))
} finally {
System.clearProperty('com.sap.piper.featureFlag.failOnMissingScript')
}
}
private static fieldRelatedWhitelist = [ private static fieldRelatedWhitelist = [
'toolValidate', // step is intended to be configured by other steps 'toolValidate', // step is intended to be configured by other steps
'durationMeasure', // only expects parameters via signature 'durationMeasure', // only expects parameters via signature
@ -130,6 +204,7 @@ public class CommonStepsTest extends BasePiperTest{
assertThat("Steps with wrong step name or without STEP_NAME field.: ${stepsWithWrongStepName}", assertThat("Steps with wrong step name or without STEP_NAME field.: ${stepsWithWrongStepName}",
stepsWithWrongStepName, is(empty())) stepsWithWrongStepName, is(empty()))
} }
/* /*
* With that test we ensure that all return types of the call methods of all the steps * With that test we ensure that all return types of the call methods of all the steps
* are void. Return types other than void are not possible when running inside declarative * are void. Return types other than void are not possible when running inside declarative
@ -165,6 +240,5 @@ public class CommonStepsTest extends BasePiperTest{
new File('vars').traverse(type: FileType.FILES, maxDepth: 0) 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 return steps
} }
} }

View File

@ -50,7 +50,7 @@ public class MtaBuildTest extends BasePiperTest {
@Test @Test
void environmentPathTest() { void environmentPathTest() {
jsr.step.call(buildTarget: 'NEO') jsr.step.call(script: nullScript, buildTarget: 'NEO')
assert jscr.shell.find { c -> c.contains('PATH=./node_modules/.bin:/usr/bin')} assert jscr.shell.find { c -> c.contains('PATH=./node_modules/.bin:/usr/bin')}
} }
@ -59,7 +59,7 @@ public class MtaBuildTest extends BasePiperTest {
@Test @Test
void sedTest() { void sedTest() {
jsr.step.call(buildTarget: 'NEO') jsr.step.call(script: nullScript, buildTarget: 'NEO')
assert jscr.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" "mta.yaml"$/} assert jscr.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" "mta.yaml"$/}
} }
@ -79,7 +79,7 @@ public class MtaBuildTest extends BasePiperTest {
@Test @Test
void mtaJarLocationAsParameterTest() { void mtaJarLocationAsParameterTest() {
jsr.step.call(mtaJarLocation: '/mylocation/mta/mta.jar', buildTarget: 'NEO') jsr.step.call(script: nullScript, mtaJarLocation: '/mylocation/mta/mta.jar', buildTarget: 'NEO')
assert jscr.shell.find { c -> c.contains('-jar /mylocation/mta/mta.jar --mtar')} assert jscr.shell.find { c -> c.contains('-jar /mylocation/mta/mta.jar --mtar')}
@ -94,7 +94,7 @@ public class MtaBuildTest extends BasePiperTest {
jryr.registerYaml('mta.yaml', { throw new FileNotFoundException() }) jryr.registerYaml('mta.yaml', { throw new FileNotFoundException() })
thrown.expect(FileNotFoundException) thrown.expect(FileNotFoundException)
jsr.step.call(buildTarget: 'NEO') jsr.step.call(script: nullScript, buildTarget: 'NEO')
} }
@ -106,7 +106,7 @@ public class MtaBuildTest extends BasePiperTest {
jryr.registerYaml('mta.yaml', badMtaYaml()) jryr.registerYaml('mta.yaml', badMtaYaml())
jsr.step.call(buildTarget: 'NEO') jsr.step.call(script: nullScript, buildTarget: 'NEO')
} }
@ -118,7 +118,7 @@ public class MtaBuildTest extends BasePiperTest {
jryr.registerYaml('mta.yaml', noIdMtaYaml() ) jryr.registerYaml('mta.yaml', noIdMtaYaml() )
jsr.step.call(buildTarget: 'NEO') jsr.step.call(script: nullScript, buildTarget: 'NEO')
} }
@ -127,7 +127,7 @@ public class MtaBuildTest extends BasePiperTest {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionWithEnvVars(m) }) helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionWithEnvVars(m) })
jsr.step.call(buildTarget: 'NEO') jsr.step.call(script: nullScript, buildTarget: 'NEO')
assert jscr.shell.find { c -> c.contains("-jar /env/mta/mta.jar --mtar")} assert jscr.shell.find { c -> c.contains("-jar /env/mta/mta.jar --mtar")}
assert jlr.log.contains("SAP Multitarget Application Archive Builder file '/env/mta/mta.jar' retrieved from environment.") assert jlr.log.contains("SAP Multitarget Application Archive Builder file '/env/mta/mta.jar' retrieved from environment.")
@ -164,7 +164,7 @@ public class MtaBuildTest extends BasePiperTest {
@Test @Test
void buildTargetFromParametersTest() { void buildTargetFromParametersTest() {
jsr.step.call(buildTarget: 'NEO') jsr.step.call(script: nullScript, buildTarget: 'NEO')
assert jscr.shell.find { c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')} assert jscr.shell.find { c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
} }
@ -210,7 +210,7 @@ public class MtaBuildTest extends BasePiperTest {
@Test @Test
void extensionFromParametersTest() { void extensionFromParametersTest() {
jsr.step.call(buildTarget: 'NEO', extension: 'param_extension') jsr.step.call(script: nullScript, buildTarget: 'NEO', extension: 'param_extension')
assert jscr.shell.find { c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO --extension=param_extension build')} assert jscr.shell.find { c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO --extension=param_extension build')}
} }

View File

@ -191,7 +191,7 @@ public class TransportRequestCreateTest extends BasePiperTest {
jlr.expect('[INFO] Change management integration intentionally switched off.') jlr.expect('[INFO] Change management integration intentionally switched off.')
jsr.step.call( jsr.step.call(script: nullScript,
changeManagement: [type: 'NONE']) changeManagement: [type: 'NONE'])
} }
} }

View File

@ -145,7 +145,7 @@ public class TransportRequestReleaseTest extends BasePiperTest {
jlr.expect('[INFO] Change management integration intentionally switched off.') jlr.expect('[INFO] Change management integration intentionally switched off.')
jsr.step.call( jsr.step.call(script: nullScript,
changeManagement: [type: 'NONE']) changeManagement: [type: 'NONE'])
} }
} }

View File

@ -373,7 +373,7 @@ public class TransportRequestUploadFileTest extends BasePiperTest {
jlr.expect('[INFO] Change management integration intentionally switched off.') jlr.expect('[INFO] Change management integration intentionally switched off.')
jsr.step.call( jsr.step.call(script: nullScript,
changeManagement: [type: 'NONE']) changeManagement: [type: 'NONE'])
} }

View File

@ -0,0 +1,71 @@
package com.sap.piper
import util.JenkinsLoggingRule
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import hudson.AbortException
import util.BasePiperTest
import util.Rules
class PrerequisitesTest extends BasePiperTest {
def result = 'SUCCESS'
@Rule
public ExpectedException thrown = ExpectedException.none()
public JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(jlr)
@Before
public void init() {
nullScript.currentBuild = [
'setResult' : { r -> result = r },
STEP_NAME: 'dummy',
]
nullScript.STEP_NAME = 'dummy'
}
@Test
public void checkScriptProvidedTest() {
def script = Prerequisites.checkScript(nullScript, [script:{}])
assert script != null
assert result == 'SUCCESS'
}
@Test
public void checkScriptMissingTest() {
jlr.expect('No reference to surrounding script provided with key \'script\'')
def script = Prerequisites.checkScript(nullScript, [:])
assert script == null
assert result == 'UNSTABLE'
}
@Test
public void checkScriptMissingTestFeatureFlagSet() {
thrown.expect(AbortException)
thrown.expectMessage('No reference to surrounding script provided')
try {
System.setProperty('com.sap.piper.featureFlag.failOnMissingScript', 'true')
Prerequisites.checkScript(nullScript, [:])
} finally {
System.clearProperty('com.sap.piper.featureFlag.failOnMissingScript')
}
}
}

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.GitUtils import com.sap.piper.GitUtils
import com.sap.piper.Utils import com.sap.piper.Utils
@ -33,17 +35,16 @@ void call(Map parameters = [:], Closure body = null) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = checkScript(this, parameters)
def gitUtils = parameters.juStabGitUtils ?: new GitUtils() def gitUtils = parameters.juStabGitUtils ?: new GitUtils()
if (gitUtils.insideWorkTree()) { if (gitUtils.insideWorkTree()) {
if (sh(returnStatus: true, script: 'git diff --quiet HEAD') != 0) if (sh(returnStatus: true, script: 'git diff --quiet HEAD') != 0)
error "[${STEP_NAME}] Files in the workspace have been changed previously - aborting ${STEP_NAME}" error "[${STEP_NAME}] Files in the workspace have been changed previously - aborting ${STEP_NAME}"
} }
def script = parameters.script
if (script == null) if (script == null)
script = this script = this
// load default & individual configuration // load default & individual configuration
ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this) ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this)
.loadStepDefaults() .loadStepDefaults()
@ -61,7 +62,7 @@ void call(Map parameters = [:], Closure body = null) {
config = configHelper.addIfEmpty('timestamp', getTimestamp(config.timestampTemplate)) config = configHelper.addIfEmpty('timestamp', getTimestamp(config.timestampTemplate))
.use() .use()
new Utils().pushToSWA([step: STEP_NAME, stepParam1: config.buildTool, stepParam2: config.artifactType], config) new Utils().pushToSWA([step: STEP_NAME, stepParam1: config.buildTool, stepParam2: config.artifactType, stepParam3: parameters?.script == null], config)
def artifactVersioning = ArtifactVersioning.getArtifactVersioning(config.buildTool, script, config) def artifactVersioning = ArtifactVersioning.getArtifactVersioning(config.buildTool, script, config)
def currentVersion = artifactVersioning.getVersion() def currentVersion = artifactVersioning.getVersion()

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.GitUtils import com.sap.piper.GitUtils
import com.sap.piper.Utils import com.sap.piper.Utils
@ -29,7 +31,8 @@ void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def utils = parameters.juStabUtils ?: new Utils() def utils = parameters.juStabUtils ?: new Utils()
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
def script = checkScript(this, parameters) ?: this
Map config = ConfigurationHelper.newInstance(this) Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults() .loadStepDefaults()
@ -40,7 +43,8 @@ void call(Map parameters = [:]) {
.use() .use()
// report to SWA // report to SWA
utils.pushToSWA([step: STEP_NAME], config) utils.pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], config)
script.commonPipelineEnvironment.setInfluxStepData('bats', false) script.commonPipelineEnvironment.setInfluxStepData('bats', false)

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.GitUtils import com.sap.piper.GitUtils
import com.sap.piper.Utils import com.sap.piper.Utils
import groovy.transform.Field import groovy.transform.Field
@ -38,7 +40,7 @@ void call(parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
GitUtils gitUtils = parameters?.gitUtils ?: new GitUtils() GitUtils gitUtils = parameters?.gitUtils ?: new GitUtils()
@ -56,8 +58,6 @@ void call(parameters = [:]) {
BackendType backendType = getBackendTypeAndLogInfoIfCMIntegrationDisabled(this, configuration) BackendType backendType = getBackendTypeAndLogInfoIfCMIntegrationDisabled(this, configuration)
if(backendType == BackendType.NONE) return if(backendType == BackendType.NONE) return
new Utils().pushToSWA([step: STEP_NAME], configuration)
configHelper configHelper
// for the following parameters we expect defaults // for the following parameters we expect defaults
/** /**
@ -94,6 +94,11 @@ void call(parameters = [:]) {
.withMandatoryProperty('changeManagement/endpoint') .withMandatoryProperty('changeManagement/endpoint')
configuration = configHelper.use()
new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
def changeId = configuration.changeDocumentId def changeId = configuration.changeDocumentId
if(changeId?.trim()) { if(changeId?.trim()) {

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.cloudbees.groovy.cps.NonCPS import com.cloudbees.groovy.cps.NonCPS
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
@ -23,9 +25,10 @@ import groovy.transform.Field
*/ */
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script
def script = checkScript(this, parameters)
if (script == null) if (script == null)
script = [commonPipelineEnvironment: commonPipelineEnvironment] script = this
prepare(parameters) prepare(parameters)
@ -38,7 +41,8 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS) .mixin(parameters, PARAMETER_KEYS)
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], configuration) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
// JAVA // JAVA
report('PmdPublisher', configuration.pmd, configuration.archive) report('PmdPublisher', configuration.pmd, configuration.archive)

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.Utils import com.sap.piper.Utils
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.CfManifestUtils import com.sap.piper.CfManifestUtils
@ -34,9 +36,9 @@ void call(Map parameters = [:]) {
utils = new Utils() utils = new Utils()
} }
def script = parameters.script def script = checkScript(this, parameters)
if (script == null) if (script == null)
script = [commonPipelineEnvironment: commonPipelineEnvironment] script = this
Map config = ConfigurationHelper.newInstance(this) Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults() .loadStepDefaults()
@ -51,7 +53,7 @@ void call(Map parameters = [:]) {
.withMandatoryProperty('cloudFoundry/credentialsId') .withMandatoryProperty('cloudFoundry/credentialsId')
.use() .use()
utils.pushToSWA([step: STEP_NAME, stepParam1: config.deployTool, stepParam2: config.deployType], config) utils.pushToSWA([step: STEP_NAME, stepParam1: config.deployTool, stepParam2: config.deployType, stepParam3: parameters?.script == null], config)
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}" 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}"

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.cloudbees.groovy.cps.NonCPS import com.cloudbees.groovy.cps.NonCPS
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
@ -32,10 +34,11 @@ import groovy.transform.Field
void call(Map parameters = [:], body) { void call(Map parameters = [:], body) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
final script = parameters.script
if (script == null) final script = checkScript(this, parameters) ?: this
script = [commonPipelineEnvironment: commonPipelineEnvironment]
def utils = parameters?.juStabUtils ?: new Utils() def utils = parameters?.juStabUtils ?: new Utils()
Map config = ConfigurationHelper.newInstance(this) Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults() .loadStepDefaults()
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS) .mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.JenkinsUtils import com.sap.piper.JenkinsUtils
import com.sap.piper.Utils import com.sap.piper.Utils
@ -24,12 +26,13 @@ import hudson.AbortException
void call(Map parameters = [:], body) { void call(Map parameters = [:], body) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
final script = checkScript(this, parameters) ?: this
if (!JenkinsUtils.isPluginActive(PLUGIN_ID_KUBERNETES)) { if (!JenkinsUtils.isPluginActive(PLUGIN_ID_KUBERNETES)) {
error("[ERROR][${STEP_NAME}] not supported. Plugin '${PLUGIN_ID_KUBERNETES}' is not installed or not active.") error("[ERROR][${STEP_NAME}] not supported. Plugin '${PLUGIN_ID_KUBERNETES}' is not installed or not active.")
} }
final script = parameters.script
if (script == null)
script = [commonPipelineEnvironment: commonPipelineEnvironment]
def utils = parameters?.juStabUtils ?: new Utils() def utils = parameters?.juStabUtils ?: new Utils()
ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this) ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this)

View File

@ -1,10 +1,12 @@
import static com.sap.piper.Prerequisites.checkScript
import groovy.transform.Field import groovy.transform.Field
@Field STEP_NAME = 'durationMeasure' @Field STEP_NAME = 'durationMeasure'
def call(Map parameters = [:], body) { def call(Map parameters = [:], body) {
def script = parameters.script def script = checkScript(this, parameters)
def measurementName = parameters.get('measurementName', 'test_duration') def measurementName = parameters.get('measurementName', 'test_duration')
//start measurement //start measurement

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.Utils import com.sap.piper.Utils
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.GitUtils import com.sap.piper.GitUtils
@ -26,7 +28,7 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
def utils = parameters.juStabUtils ?: new Utils() def utils = parameters.juStabUtils ?: new Utils()
script.commonPipelineEnvironment.setInfluxStepData('gauge', false) script.commonPipelineEnvironment.setInfluxStepData('gauge', false)

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.Utils import com.sap.piper.Utils
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
@ -22,7 +24,7 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
// load default & individual configuration // load default & individual configuration
Map config = ConfigurationHelper.newInstance(this) Map config = ConfigurationHelper.newInstance(this)

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.Utils import com.sap.piper.Utils
import groovy.transform.Field import groovy.transform.Field
@ -15,7 +17,7 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
// load default & individual configuration // load default & individual configuration
Map config = ConfigurationHelper.newInstance(this) Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults() .loadStepDefaults()

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.ConfigurationLoader import com.sap.piper.ConfigurationLoader
import com.sap.piper.ConfigurationMerger import com.sap.piper.ConfigurationMerger
@ -19,9 +21,10 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) {
def script = parameters.script
def script = checkScript(this, parameters)
if (script == null) if (script == null)
script = [commonPipelineEnvironment: commonPipelineEnvironment] script = this
// load default & individual configuration // load default & individual configuration
Map configuration = ConfigurationHelper.newInstance(this) Map configuration = ConfigurationHelper.newInstance(this)
@ -35,7 +38,8 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS) .mixin(parameters, PARAMETER_KEYS)
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], configuration) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
if (!configuration.artifactVersion) { if (!configuration.artifactVersion) {
//this takes care that terminated builds due to milestone-locking do not cause an error //this takes care that terminated builds due to milestone-locking do not cause an error

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.Utils import com.sap.piper.Utils
import groovy.text.SimpleTemplateEngine import groovy.text.SimpleTemplateEngine
@ -21,7 +23,7 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) {
def script = parameters.script?:[commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
// load default & individual configuration // load default & individual configuration
Map config = ConfigurationHelper.newInstance(this) Map config = ConfigurationHelper.newInstance(this)

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.Utils import com.sap.piper.Utils
@ -23,7 +25,8 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
final script = parameters.script
final script = checkScript(this, parameters) ?: this
// load default & individual configuration // load default & individual configuration
Map configuration = ConfigurationHelper.newInstance(this) Map configuration = ConfigurationHelper.newInstance(this)
@ -34,7 +37,8 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS) .mixin(parameters, PARAMETER_KEYS)
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], configuration) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
String command = "mvn" String command = "mvn"

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.MtaUtils import com.sap.piper.MtaUtils
import com.sap.piper.Utils import com.sap.piper.Utils
@ -22,7 +24,8 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
final script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
final script = checkScript(this, parameters) ?: this
// load default & individual configuration // load default & individual configuration
Map configuration = ConfigurationHelper.newInstance(this) Map configuration = ConfigurationHelper.newInstance(this)
@ -33,7 +36,8 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS) .mixin(parameters, PARAMETER_KEYS)
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], configuration) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
dockerExecute(script: script, dockerImage: configuration.dockerImage, dockerOptions: configuration.dockerOptions) { dockerExecute(script: script, dockerImage: configuration.dockerImage, dockerOptions: configuration.dockerOptions) {
def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1') def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.Utils import com.sap.piper.Utils
@ -32,7 +34,8 @@ import groovy.transform.Field
void call(parameters = [:]) { void call(parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
def utils = new Utils() def utils = new Utils()
prepareDefaultValues script: script prepareDefaultValues script: script
@ -85,7 +88,8 @@ void call(parameters = [:]) {
utils.pushToSWA([ utils.pushToSWA([
step: STEP_NAME, step: STEP_NAME,
stepParam1: configuration.deployMode == 'mta'?'mta':'war', // ['mta', 'warParams', 'warPropertiesFile'] stepParam1: configuration.deployMode == 'mta'?'mta':'war', // ['mta', 'warParams', 'warPropertiesFile']
stepParam2: configuration.warAction == 'rolling-update'?'blue-green':'standard' // ['deploy', 'deploy-mta', 'rolling-update'] stepParam2: configuration.warAction == 'rolling-update'?'blue-green':'standard', // ['deploy', 'deploy-mta', 'rolling-update']
stepParam3: parameters?.script == null
], configuration) ], configuration)
def archivePath = configuration.archivePath def archivePath = configuration.archivePath

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.GitUtils import com.sap.piper.GitUtils
import com.sap.piper.Utils import com.sap.piper.Utils
@ -25,7 +27,9 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
def script = checkScript(this, parameters) ?: this
def utils = parameters?.juStabUtils ?: new Utils() def utils = parameters?.juStabUtils ?: new Utils()
// load default & individual configuration // load default & individual configuration
@ -37,7 +41,8 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS) .mixin(parameters, PARAMETER_KEYS)
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], config) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], config)
config.stashContent = config.testRepository config.stashContent = config.testRepository
?[GitUtils.handleTestRepository(this, config)] ?[GitUtils.handleTestRepository(this, config)]

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.JenkinsUtils import com.sap.piper.JenkinsUtils
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import groovy.transform.Field import groovy.transform.Field
@ -11,7 +13,7 @@ import groovy.transform.Field
void call(Map parameters = [:], body) { void call(Map parameters = [:], body) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
def jenkinsUtils = parameters.jenkinsUtilsStub ?: new JenkinsUtils() def jenkinsUtils = parameters.jenkinsUtilsStub ?: new JenkinsUtils()
// load default & individual configuration // load default & individual configuration
Map config = ConfigurationHelper.newInstance(this) Map config = ConfigurationHelper.newInstance(this)

View File

@ -4,6 +4,7 @@ import groovy.transform.Field
void call(Map parameters = [:], body) { void call(Map parameters = [:], body) {
handlePipelineStepErrors (stepName: 'pipelineStashFiles', stepParameters: parameters) { handlePipelineStepErrors (stepName: 'pipelineStashFiles', stepParameters: parameters) {
pipelineStashFilesBeforeBuild(parameters) pipelineStashFilesBeforeBuild(parameters)
body() //execute build body() //execute build
pipelineStashFilesAfterBuild(parameters) pipelineStashFilesAfterBuild(parameters)

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.Utils import com.sap.piper.Utils
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import groovy.transform.Field import groovy.transform.Field
@ -13,9 +15,10 @@ void call(Map parameters = [:]) {
if (utils == null) { if (utils == null) {
utils = new Utils() utils = new Utils()
} }
def script = parameters.script
def script = checkScript(this, parameters)
if (script == null) if (script == null)
script = [commonPipelineEnvironment: commonPipelineEnvironment] script = this
//additional includes via passing e.g. stashIncludes: [opa5: '**/*.include'] //additional includes via passing e.g. stashIncludes: [opa5: '**/*.include']
//additional excludes via passing e.g. stashExcludes: [opa5: '**/*.exclude'] //additional excludes via passing e.g. stashExcludes: [opa5: '**/*.exclude']
@ -31,7 +34,8 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS) .mixin(parameters, PARAMETER_KEYS)
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], config) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], config)
// store files to be checked with checkmarx // store files to be checked with checkmarx
if (config.runCheckmarx) { if (config.runCheckmarx) {

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.Utils import com.sap.piper.Utils
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import groovy.transform.Field import groovy.transform.Field
@ -15,9 +17,9 @@ void call(Map parameters = [:]) {
utils = new Utils() utils = new Utils()
} }
def script = parameters.script def script = checkScript(this, parameters)
if (script == null) if (script == null)
script = [commonPipelineEnvironment: commonPipelineEnvironment] script = this
//additional includes via passing e.g. stashIncludes: [opa5: '**/*.include'] //additional includes via passing e.g. stashIncludes: [opa5: '**/*.include']
//additional excludes via passing e.g. stashExcludes: [opa5: '**/*.exclude'] //additional excludes via passing e.g. stashExcludes: [opa5: '**/*.exclude']
@ -30,7 +32,8 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS) .mixin(parameters, PARAMETER_KEYS)
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], config) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], config)
if (config.runOpaTests){ if (config.runOpaTests){
utils.stash('opa5', config.stashIncludes?.get('opa5')?config.stashIncludes.opa5:'**/*.*', config.stashExcludes?.get('opa5')?config.stashExcludes.opa5:'') utils.stash('opa5', config.stashIncludes?.get('opa5')?config.stashIncludes.opa5:'**/*.*', config.stashExcludes?.get('opa5')?config.stashExcludes.opa5:'')

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.GitUtils import com.sap.piper.GitUtils
import com.sap.piper.Utils import com.sap.piper.Utils
@ -31,7 +33,7 @@ import groovy.text.SimpleTemplateEngine
void call(Map parameters = [:], Closure body) { void call(Map parameters = [:], Closure body) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
def utils = parameters?.juStabUtils ?: new Utils() def utils = parameters?.juStabUtils ?: new Utils()
// load default & individual configuration // load default & individual configuration
@ -46,7 +48,8 @@ void call(Map parameters = [:], Closure body) {
.dependingOn('buildTool').mixin('dockerWorkspace') .dependingOn('buildTool').mixin('dockerWorkspace')
.use() .use()
utils.pushToSWA([step: STEP_NAME], config) utils.pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], config)
dockerExecute( dockerExecute(
script: script, script: script,

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.Utils import com.sap.piper.Utils
import groovy.transform.Field import groovy.transform.Field
@ -9,7 +11,7 @@ void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script def script = checkScript(this, parameters)
prepareDefaultValues script: script, customDefaults: parameters.customDefaults prepareDefaultValues script: script, customDefaults: parameters.customDefaults

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
import com.sap.piper.Utils import com.sap.piper.Utils
import com.sap.piper.mta.MtaMultiplexer import com.sap.piper.mta.MtaMultiplexer
@ -22,7 +24,8 @@ import groovy.transform.Field
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def utils = parameters.juStabUtils ?: new Utils() def utils = parameters.juStabUtils ?: new Utils()
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
def script = checkScript(this, parameters) ?: this
Map config = ConfigurationHelper.newInstance(this) Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults() .loadStepDefaults()
@ -35,7 +38,8 @@ void call(Map parameters = [:]) {
.withMandatoryProperty('snykCredentialsId') .withMandatoryProperty('snykCredentialsId')
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], config) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], config)
utils.unstashAll(config.stashContent) utils.unstashAll(config.stashContent)

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.cloudbees.groovy.cps.NonCPS import com.cloudbees.groovy.cps.NonCPS
import com.sap.piper.ConfigurationHelper import com.sap.piper.ConfigurationHelper
@ -22,9 +24,11 @@ import groovy.transform.Field
*/ */
void call(Map parameters = [:]) { void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script
def script = checkScript(this, parameters)
if (script == null) if (script == null)
script = [commonPipelineEnvironment: commonPipelineEnvironment] script = this
prepare(parameters) prepare(parameters)
// load default & individual configuration // load default & individual configuration
@ -36,7 +40,8 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS) .mixin(parameters, PARAMETER_KEYS)
.use() .use()
new Utils().pushToSWA([step: STEP_NAME], configuration) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
// UNIT TESTS // UNIT TESTS
publishJUnitReport(configuration.get('junit')) publishJUnitReport(configuration.get('junit'))

View File

@ -2,6 +2,7 @@ import com.sap.piper.FileUtils
import com.sap.piper.Version import com.sap.piper.Version
import com.sap.piper.tools.JavaArchiveDescriptor import com.sap.piper.tools.JavaArchiveDescriptor
import com.sap.piper.tools.ToolDescriptor import com.sap.piper.tools.ToolDescriptor
import groovy.transform.Field
import groovy.transform.Field import groovy.transform.Field

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.Utils import com.sap.piper.Utils
import groovy.transform.Field import groovy.transform.Field
@ -30,7 +32,7 @@ def call(parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script) ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
@ -47,8 +49,6 @@ def call(parameters = [:]) {
BackendType backendType = getBackendTypeAndLogInfoIfCMIntegrationDisabled(this, configuration) BackendType backendType = getBackendTypeAndLogInfoIfCMIntegrationDisabled(this, configuration)
if(backendType == BackendType.NONE) return if(backendType == BackendType.NONE) return
new Utils().pushToSWA([step: STEP_NAME], configuration)
configHelper configHelper
.withMandatoryProperty('changeManagement/clientOpts') .withMandatoryProperty('changeManagement/clientOpts')
.withMandatoryProperty('changeManagement/credentialsId') .withMandatoryProperty('changeManagement/credentialsId')
@ -62,6 +62,9 @@ def call(parameters = [:]) {
def changeDocumentId = null def changeDocumentId = null
new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
if(backendType == BackendType.SOLMAN) { if(backendType == BackendType.SOLMAN) {
changeDocumentId = configuration.changeDocumentId changeDocumentId = configuration.changeDocumentId

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.Utils import com.sap.piper.Utils
import groovy.transform.Field import groovy.transform.Field
@ -27,7 +29,7 @@ void call(parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script) ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
@ -52,7 +54,10 @@ void call(parameters = [:]) {
.withMandatoryProperty('changeManagement/git/from') .withMandatoryProperty('changeManagement/git/from')
.withMandatoryProperty('changeManagement/git/format') .withMandatoryProperty('changeManagement/git/format')
new Utils().pushToSWA([step: STEP_NAME], configuration) configuration = configHelper.use()
new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
def transportRequestId = configuration.transportRequestId def transportRequestId = configuration.transportRequestId

View File

@ -1,3 +1,5 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.Utils import com.sap.piper.Utils
import groovy.transform.Field import groovy.transform.Field
@ -29,7 +31,7 @@ void call(parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) { handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment] def script = checkScript(this, parameters) ?: this
ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script) ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
@ -57,7 +59,9 @@ void call(parameters = [:]) {
.withMandatoryProperty('changeManagement/git/format') .withMandatoryProperty('changeManagement/git/format')
.withMandatoryProperty('filePath') .withMandatoryProperty('filePath')
new Utils().pushToSWA([step: STEP_NAME, stepParam1: configuration.changeManagement.type], configuration) new Utils().pushToSWA([step: STEP_NAME,
stepParam1: configuration.changeManagement.type,
stepParam2: parameters?.script == null], configuration)
def changeDocumentId = null def changeDocumentId = null