mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-05 13:25:19 +02:00
Ensure script is mandatory parameter
... only in case a step uses the script at all.
This commit is contained in:
parent
3d2bc3f892
commit
c03a75da9f
27
src/com/sap/piper/Prerequisites.groovy
Normal file
27
src/com/sap/piper/Prerequisites.groovy
Normal file
@ -0,0 +1,27 @@
|
||||
package com.sap.piper
|
||||
|
||||
import static java.lang.Boolean.getBoolean
|
||||
|
||||
/**
|
||||
* @return <code>true</code> in case the script has been provided. <code>false</code> otherwise.
|
||||
*/
|
||||
static checkScript(def step, Map params) {
|
||||
|
||||
def script = params?.script
|
||||
|
||||
if(script == null) {
|
||||
|
||||
step.currentBuild.status = '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 '${step.currentBuild.status}'. In future versions of piper-lib the build will fail."
|
||||
|
||||
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'.")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return script
|
||||
}
|
@ -8,6 +8,7 @@ import org.junit.rules.RuleChain
|
||||
|
||||
import com.sap.piper.GitUtils
|
||||
|
||||
import hudson.AbortException
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsDockerExecuteRule
|
||||
import util.JenkinsEnvironmentRule
|
||||
@ -109,14 +110,6 @@ class ArtifactSetVersionTest extends BasePiperTest {
|
||||
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
|
||||
void testVersioningCustomGitUserAndEMail() {
|
||||
jsr.step.artifactSetVersion(script: jsr.step, juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl', gitUserEMail: 'test@test.com', gitUserName: 'test')
|
||||
|
@ -41,6 +41,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
|
||||
ChangeManagement cm = getChangeManagementUtils(true)
|
||||
boolean inDevelopment = jsr.step.checkChangeInDevelopment(
|
||||
script: nullScript,
|
||||
cmUtils: cm,
|
||||
changeManagement: [endpoint: 'https://example.org/cm'])
|
||||
|
||||
@ -61,6 +62,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
|
||||
ChangeManagement cm = getChangeManagementUtils(false)
|
||||
jsr.step.checkChangeInDevelopment(
|
||||
script: nullScript,
|
||||
cmUtils: cm,
|
||||
changeManagement: [endpoint: 'https://example.org/cm'])
|
||||
}
|
||||
@ -70,6 +72,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
|
||||
ChangeManagement cm = getChangeManagementUtils(false)
|
||||
boolean inDevelopment = jsr.step.checkChangeInDevelopment(
|
||||
script: nullScript,
|
||||
cmUtils: cm,
|
||||
changeManagement: [endpoint: 'https://example.org/cm'],
|
||||
failIfStatusIsNotInDevelopment: false)
|
||||
@ -81,6 +84,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
ChangeManagement cm = getChangeManagementUtils(true, '0815')
|
||||
|
||||
jsr.step.checkChangeInDevelopment(
|
||||
script: nullScript,
|
||||
changeDocumentId: '42',
|
||||
cmUtils: cm,
|
||||
changeManagement: [endpoint: 'https://example.org/cm'])
|
||||
@ -93,6 +97,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
ChangeManagement cm = getChangeManagementUtils(true, '0815')
|
||||
|
||||
jsr.step.checkChangeInDevelopment(
|
||||
script: nullScript,
|
||||
cmUtils: cm,
|
||||
changeManagement : [endpoint: 'https://example.org/cm'])
|
||||
|
||||
@ -118,6 +123,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
}
|
||||
|
||||
jsr.step.checkChangeInDevelopment(
|
||||
script: nullScript,
|
||||
cmUtils: cm,
|
||||
changeManagement: [endpoint: 'https://example.org/cm'])
|
||||
}
|
||||
@ -132,6 +138,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
|
||||
ChangeManagement cm = getChangeManagementUtils(false, null)
|
||||
jsr.step.checkChangeInDevelopment(
|
||||
script: nullScript,
|
||||
cmUtils: cm,
|
||||
changeManagement: [endpoint: 'https://example.org/cm'])
|
||||
}
|
||||
@ -146,6 +153,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
|
||||
ChangeManagement cm = getChangeManagementUtils(false, '')
|
||||
jsr.step.checkChangeInDevelopment(
|
||||
script: nullScript,
|
||||
cmUtils: cm,
|
||||
changeManagement: [endpoint: 'https://example.org/cm'])
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishWithDefaultSettings() throws Exception {
|
||||
jsr.step.call()
|
||||
jsr.step.call(script: nullScript)
|
||||
|
||||
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
||||
// ensure nothing else is published
|
||||
@ -56,7 +56,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
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("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
||||
@ -74,7 +74,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
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("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
|
||||
@ -92,7 +92,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
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("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
|
||||
@ -111,7 +111,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishNothing() throws Exception {
|
||||
jsr.step.call(aggregation: false)
|
||||
jsr.step.call(script: nullScript, aggregation: false)
|
||||
|
||||
// ensure nothing is published
|
||||
assertTrue("AnalysisPublisher options not empty", publisherStepOptions['AnalysisPublisher'] == null)
|
||||
@ -124,7 +124,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishNothingExplicitFalse() throws Exception {
|
||||
jsr.step.call(pmd: false)
|
||||
jsr.step.call(script: nullScript, pmd: false)
|
||||
|
||||
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
|
||||
// ensure nothing else is published
|
||||
@ -137,7 +137,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishNothingImplicitTrue() throws Exception {
|
||||
jsr.step.call(pmd: [:])
|
||||
jsr.step.call(script: nullScript, pmd: [:])
|
||||
|
||||
// ensure pmd is not published
|
||||
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
||||
@ -145,7 +145,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishNothingExplicitActiveFalse() throws Exception {
|
||||
jsr.step.call(pmd: [active: false])
|
||||
jsr.step.call(script: nullScript, pmd: [active: false])
|
||||
|
||||
// ensure pmd is not published
|
||||
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
|
||||
@ -169,7 +169,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
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("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
||||
@ -186,7 +186,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
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 contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
|
||||
@ -198,7 +198,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
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 contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
|
||||
@ -211,7 +211,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishWithDefaultThresholds() throws Exception {
|
||||
jsr.step.call(pmd: true)
|
||||
jsr.step.call(script: nullScript, pmd: true)
|
||||
|
||||
assertTrue("AnalysisPublisher options not set",
|
||||
publisherStepOptions['AnalysisPublisher'] != null)
|
||||
@ -245,7 +245,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
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("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
|
||||
|
107
test/groovy/CommonStepsTest.groovy
Normal file
107
test/groovy/CommonStepsTest.groovy
Normal file
@ -0,0 +1,107 @@
|
||||
import static java.util.stream.Collectors.toList
|
||||
import static org.hamcrest.Matchers.empty
|
||||
import static org.hamcrest.Matchers.equalTo
|
||||
import static org.hamcrest.Matchers.is
|
||||
import static org.junit.Assert.assertThat
|
||||
import static org.junit.Assert.fail
|
||||
|
||||
import java.io.File;
|
||||
import java.util.stream.Collectors
|
||||
|
||||
import org.codehaus.groovy.runtime.metaclass.MethodSelectionException
|
||||
import org.hamcrest.Matchers
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import groovy.io.FileType
|
||||
import hudson.AbortException
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
|
||||
/*
|
||||
* Intended for collecting generic checks applied to all steps.
|
||||
*/
|
||||
public class CommonStepsTest extends BasePiperTest{
|
||||
|
||||
@Rule
|
||||
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 static List getSteps() {
|
||||
List steps = []
|
||||
new File('vars').traverse(type: FileType.FILES, maxDepth: 0)
|
||||
{ if(it.getName().endsWith('.groovy')) steps << (it =~ /vars\/(.*)\.groovy/)[0][1] }
|
||||
return steps
|
||||
|
||||
}
|
||||
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')
|
||||
}
|
||||
}
|
||||
}
|
@ -117,7 +117,7 @@ class DockerExecuteTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testExecuteInsideDockerNoScript() throws Exception {
|
||||
jsr.step.dockerExecute(dockerImage: 'maven:3.5-jdk-8-alpine') {
|
||||
jsr.step.dockerExecute(script: nullScript, dockerImage: 'maven:3.5-jdk-8-alpine') {
|
||||
bodyExecuted = true
|
||||
}
|
||||
assertEquals('maven:3.5-jdk-8-alpine', docker.getImageName())
|
||||
|
@ -50,7 +50,7 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
@Test
|
||||
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')}
|
||||
}
|
||||
@ -59,7 +59,7 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
@Test
|
||||
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"$/}
|
||||
}
|
||||
@ -79,7 +79,7 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
@Test
|
||||
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')}
|
||||
|
||||
@ -94,7 +94,7 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
jryr.registerYaml('mta.yaml', { throw new 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())
|
||||
|
||||
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() )
|
||||
|
||||
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) })
|
||||
|
||||
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 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
|
||||
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')}
|
||||
}
|
||||
@ -210,7 +210,7 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
@Test
|
||||
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')}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class TestsPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishNothingWithDefaultSettings() throws Exception {
|
||||
jsr.step.testsPublishResults()
|
||||
jsr.step.testsPublishResults(script: nullScript)
|
||||
|
||||
// ensure nothing is published
|
||||
assertTrue('WarningsPublisher options not empty', publisherStepOptions.junit == null)
|
||||
@ -59,7 +59,7 @@ class TestsPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishNothingWithAllDisabled() throws Exception {
|
||||
jsr.step.testsPublishResults(junit: false, jacoco: false, cobertura: false, jmeter: false)
|
||||
jsr.step.testsPublishResults(script: nullScript, junit: false, jacoco: false, cobertura: false, jmeter: false)
|
||||
|
||||
// ensure nothing is published
|
||||
assertTrue('WarningsPublisher options not empty', publisherStepOptions.junit == null)
|
||||
@ -70,7 +70,7 @@ class TestsPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishUnitTestsWithDefaultSettings() throws Exception {
|
||||
jsr.step.testsPublishResults(junit: true)
|
||||
jsr.step.testsPublishResults(script: nullScript, junit: true)
|
||||
|
||||
assertTrue('JUnit options are empty', publisherStepOptions.junit != null)
|
||||
// ensure default patterns are set
|
||||
@ -84,7 +84,7 @@ class TestsPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishCoverageWithDefaultSettings() throws Exception {
|
||||
jsr.step.testsPublishResults(jacoco: true, cobertura: true)
|
||||
jsr.step.testsPublishResults(script: nullScript, jacoco: true, cobertura: true)
|
||||
|
||||
assertTrue('JaCoCo options are empty', publisherStepOptions.jacoco != null)
|
||||
assertTrue('Cobertura options are empty', publisherStepOptions.cobertura != null)
|
||||
@ -99,7 +99,7 @@ class TestsPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishJMeterWithDefaultSettings() throws Exception {
|
||||
jsr.step.testsPublishResults(jmeter: true)
|
||||
jsr.step.testsPublishResults(script: nullScript, jmeter: true)
|
||||
|
||||
assertTrue('JMeter options are empty', publisherStepOptions.jmeter != null)
|
||||
assertEquals('JMeter default pattern not set',
|
||||
@ -113,7 +113,7 @@ class TestsPublishResultsTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testPublishUnitTestsWithCustomSettings() throws Exception {
|
||||
jsr.step.testsPublishResults(junit: [pattern: 'fancy/file/path', archive: true, active: true])
|
||||
jsr.step.testsPublishResults(script: nullScript, junit: [pattern: 'fancy/file/path', archive: true, active: true])
|
||||
|
||||
assertTrue('JUnit options are empty', publisherStepOptions.junit != null)
|
||||
// ensure default patterns are set
|
||||
|
67
test/groovy/com/sap/piper/PrerequisitesTest.groovy
Normal file
67
test/groovy/com/sap/piper/PrerequisitesTest.groovy
Normal file
@ -0,0 +1,67 @@
|
||||
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 {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none()
|
||||
|
||||
@Rule
|
||||
public JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this)
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
nullScript.metaClass.STEP_NAME = 'dummy'
|
||||
nullScript.currentBuild.status = 'SUCCESS'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkScriptProvidedTest() {
|
||||
|
||||
def script = Prerequisites.checkScript(nullScript, [script:{}])
|
||||
|
||||
assert script != null
|
||||
assert nullScript.currentBuild.status == 'SUCCESS'
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkScriptMissingTest() {
|
||||
|
||||
jlr.expect('No reference to surrounding script provided with key \'script\'')
|
||||
assert nullScript.currentBuild.status == 'SUCCESS'
|
||||
|
||||
def script = Prerequisites.checkScript(nullScript, [:])
|
||||
|
||||
assert script == null
|
||||
assert nullScript.currentBuild.status == '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')
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
@ -29,17 +31,16 @@ def call(Map parameters = [:], Closure body = null) {
|
||||
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
def script = checkScript(this, parameters)
|
||||
|
||||
def gitUtils = parameters.juStabGitUtils ?: new GitUtils()
|
||||
|
||||
if (gitUtils.insideWorkTree()) {
|
||||
if (sh(returnStatus: true, script: 'git diff --quiet HEAD') != 0)
|
||||
error "[${STEP_NAME}] Files in the workspace have been changed previously - aborting ${STEP_NAME}"
|
||||
}
|
||||
|
||||
def script = parameters.script
|
||||
if (script == null)
|
||||
script = this
|
||||
|
||||
// load default & individual configuration
|
||||
ConfigurationHelper configHelper = ConfigurationHelper
|
||||
.loadStepDefaults(this)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
@ -25,7 +27,8 @@ def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
def utils = parameters.juStabUtils ?: new Utils()
|
||||
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
Map config = ConfigurationHelper
|
||||
.loadStepDefaults(this)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
import groovy.transform.Field
|
||||
@ -23,7 +25,7 @@ def call(parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
GitUtils gitUtils = parameters?.gitUtils ?: new GitUtils()
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
@ -23,7 +25,8 @@ import groovy.transform.Field
|
||||
*/
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
def script = parameters.script
|
||||
|
||||
def script = checkScript(this, parameters)
|
||||
if (script == null)
|
||||
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
|
||||
@ -29,7 +31,7 @@ def call(Map parameters = [:]) {
|
||||
utils = new Utils()
|
||||
}
|
||||
|
||||
def script = parameters.script
|
||||
def script = checkScript(this, parameters)
|
||||
if (script == null)
|
||||
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.k8s.ContainerMap
|
||||
@ -28,9 +30,9 @@ import groovy.transform.Field
|
||||
|
||||
void call(Map parameters = [:], body) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
final script = parameters.script
|
||||
if (script == null)
|
||||
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
final script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
Map config = ConfigurationHelper
|
||||
.loadStepDefaults(this)
|
||||
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.JenkinsUtils
|
||||
import com.sap.piper.k8s.SystemEnv
|
||||
@ -22,12 +24,12 @@ import hudson.AbortException
|
||||
|
||||
void call(Map parameters = [:], body) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
final script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
if (!JenkinsUtils.isPluginActive(PLUGIN_ID_KUBERNETES)) {
|
||||
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]
|
||||
|
||||
ConfigurationHelper configHelper = ConfigurationHelper
|
||||
.loadStepDefaults(this)
|
||||
|
@ -1,6 +1,12 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
import groovy.transform.Field
|
||||
|
||||
@Field STEP_NAME='durationMeasure'
|
||||
|
||||
def call(Map parameters = [:], body) {
|
||||
|
||||
def script = parameters.script
|
||||
def script = checkScript(this, parameters)
|
||||
|
||||
def measurementName = parameters.get('measurementName', 'test_duration')
|
||||
|
||||
//start measurement
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.ConfigurationLoader
|
||||
import com.sap.piper.ConfigurationMerger
|
||||
@ -19,7 +21,8 @@ import groovy.transform.Field
|
||||
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) {
|
||||
def script = parameters.script
|
||||
|
||||
def script = checkScript(this, parameters)
|
||||
if (script == null)
|
||||
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.Utils
|
||||
|
||||
@ -23,7 +25,8 @@ import groovy.transform.Field
|
||||
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
final script = parameters.script
|
||||
|
||||
final script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
// load default & individual configuration
|
||||
Map configuration = ConfigurationHelper
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.MtaUtils
|
||||
import com.sap.piper.Utils
|
||||
@ -22,7 +24,8 @@ import groovy.transform.Field
|
||||
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
final script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
final script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
// load default & individual configuration
|
||||
Map configuration = ConfigurationHelper
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.Utils
|
||||
|
||||
@ -32,7 +34,8 @@ import groovy.transform.Field
|
||||
def call(parameters = [:]) {
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
def utils = new Utils()
|
||||
|
||||
prepareDefaultValues script: script
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
@ -21,7 +23,9 @@ import groovy.transform.Field
|
||||
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
def utils = parameters?.juStabUtils ?: new Utils()
|
||||
|
||||
// load default & individual configuration
|
||||
|
@ -1,5 +1,6 @@
|
||||
def call(Map parameters = [:], body) {
|
||||
handlePipelineStepErrors (stepName: 'pipelineStashFiles', stepParameters: parameters) {
|
||||
|
||||
pipelineStashFilesBeforeBuild(parameters)
|
||||
body() //execute build
|
||||
pipelineStashFilesAfterBuild(parameters)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import groovy.transform.Field
|
||||
@ -13,7 +15,8 @@ def call(Map parameters = [:]) {
|
||||
if (utils == null) {
|
||||
utils = new Utils()
|
||||
}
|
||||
def script = parameters.script
|
||||
|
||||
def script = checkScript(this, parameters)
|
||||
if (script == null)
|
||||
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import groovy.transform.Field
|
||||
@ -15,7 +17,7 @@ def call(Map parameters = [:]) {
|
||||
utils = new Utils()
|
||||
}
|
||||
|
||||
def script = parameters.script
|
||||
def script = checkScript(this, parameters)
|
||||
if (script == null)
|
||||
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
@ -25,7 +27,7 @@ import groovy.text.SimpleTemplateEngine
|
||||
|
||||
def call(Map parameters = [:], Closure body) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
def utils = parameters?.juStabUtils ?: new Utils()
|
||||
|
||||
// load default & individual configuration
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.Utils
|
||||
import groovy.transform.Field
|
||||
@ -9,7 +11,7 @@ def call(Map parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
def script = parameters.script
|
||||
def script = checkScript(this, parameters)
|
||||
|
||||
prepareDefaultValues script: script, customDefaults: parameters.customDefaults
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.mta.MtaMultiplexer
|
||||
@ -22,7 +24,8 @@ import groovy.transform.Field
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
def utils = parameters.juStabUtils ?: new Utils()
|
||||
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
Map config = ConfigurationHelper
|
||||
.loadStepDefaults(this)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
@ -21,9 +23,11 @@ import groovy.transform.Field
|
||||
*/
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
def script = parameters.script
|
||||
|
||||
def script = checkScript(this, parameters)
|
||||
if (script == null)
|
||||
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
prepare(parameters)
|
||||
|
||||
// load default & individual configuration
|
||||
|
@ -2,10 +2,13 @@ import com.sap.piper.FileUtils
|
||||
import com.sap.piper.Version
|
||||
import com.sap.piper.tools.JavaArchiveDescriptor
|
||||
import com.sap.piper.tools.ToolDescriptor
|
||||
import groovy.transform.Field
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
|
||||
@Field def STEP_NAME='toolValidate'
|
||||
|
||||
def call(Map parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: 'toolValidate', stepParameters: parameters) {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.Utils
|
||||
import groovy.transform.Field
|
||||
|
||||
@ -23,7 +25,7 @@ def call(parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.Utils
|
||||
import groovy.transform.Field
|
||||
|
||||
@ -25,7 +27,7 @@ def call(parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.Utils
|
||||
import groovy.transform.Field
|
||||
|
||||
@ -27,7 +29,7 @@ def call(parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
def script = checkScript(this, parameters) ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user