Skip to content

Commit

Permalink
Merge pull request #319 from marcusholl/pr/stepReturnVoid
Browse files Browse the repository at this point in the history
Pr/step return void
  • Loading branch information
marcusholl committed Oct 18, 2018
2 parents 43acbcf + 6653b68 commit 63dd8f4
Show file tree
Hide file tree
Showing 28 changed files with 70 additions and 38 deletions.
10 changes: 6 additions & 4 deletions test/groovy/CheckChangeInDevelopmentTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
public void changeIsInStatusDevelopmentTest() {

ChangeManagement cm = getChangeManagementUtils(true)
boolean inDevelopment = jsr.step.checkChangeInDevelopment(
cmUtils: cm,
changeManagement: [endpoint: 'https://example.org/cm'])
jsr.step.checkChangeInDevelopment(
cmUtils: cm,
changeManagement: [endpoint: 'https://example.org/cm'],
failIfStatusIsNotInDevelopment: true)

assert inDevelopment
assert cmUtilReceivedParams == [
changeId: '001',
endpoint: 'https://example.org/cm',
credentialsId: 'CM',
cmclientOpts: ''
]

// no exception in thrown, so the change is in status 'in development'.
}

@Test
Expand Down
32 changes: 32 additions & 0 deletions test/groovy/CommonStepsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import static java.util.stream.Collectors.toList
import static org.hamcrest.Matchers.empty
import static org.hamcrest.Matchers.is
import static org.junit.Assert.assertThat
import static org.junit.Assert.fail

import java.lang.reflect.Field
import java.io.File;

import org.junit.Assert
import org.junit.Rule
Expand All @@ -12,6 +14,7 @@ import org.junit.rules.RuleChain

import groovy.io.FileType
import util.BasePiperTest

import util.Rules

/*
Expand Down Expand Up @@ -64,6 +67,35 @@ public class CommonStepsTest extends BasePiperTest{
assertThat("Steps with wrong step name or without STEP_NAME field.: ${stepsWithWrongStepName}",
stepsWithWrongStepName, is(empty()))
}
/*
* 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
* pipelines. Parameters shared between several steps needs to be shared via the commonPipelineEnvironment.
*/
@Test
public void returnTypeForCallMethodsIsVoidTest() {

def stepsWithCallMethodsOtherThanVoid = []

def whitelist = [
'transportRequestCreate',
'durationMeasure',
]

for(def step in getSteps()) {
def methods = loadScript("${step}.groovy").getClass().getDeclaredMethods() as List
Collection callMethodsWithReturnTypeOtherThanVoid =
methods.stream()
.filter { ! whitelist.contains(step) }
.filter { it.getName() == 'call' &&
it.getReturnType() != Void.TYPE }
.collect(toList())
if(!callMethodsWithReturnTypeOtherThanVoid.isEmpty()) stepsWithCallMethodsOtherThanVoid << step
}

assertThat("Steps with call methods with return types other than void: ${stepsWithCallMethodsOtherThanVoid}",
stepsWithCallMethodsOtherThanVoid, is(empty()))
}

private static getSteps() {
List steps = []
Expand Down
1 change: 0 additions & 1 deletion test/groovy/TransportRequestCreateTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public class TransportRequestCreateTest extends BasePiperTest {
result.developmentSystemId = developmentSystemId
result.cmEndpoint = cmEndpoint
result.credentialId = credentialId

result.clientOpts = clientOpts
return '001'
}
Expand Down
2 changes: 1 addition & 1 deletion vars/artifactSetVersion.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import groovy.text.SimpleTemplateEngine
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus('gitCommitId')

def call(Map parameters = [:], Closure body = null) {
void call(Map parameters = [:], Closure body = null) {

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

Expand Down
2 changes: 1 addition & 1 deletion vars/batsExecuteTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import groovy.transform.Field
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

def utils = parameters.juStabUtils ?: new Utils()
Expand Down
4 changes: 1 addition & 3 deletions vars/checkChangeInDevelopment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.sap.piper.cm.ChangeManagementException

@Field Set generalConfigurationKeys = stepConfigurationKeys

def call(parameters = [:]) {
void call(parameters = [:]) {

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

Expand Down Expand Up @@ -103,14 +103,12 @@ def call(parameters = [:]) {

if(isInDevelopment) {
echo "[INFO] Change '${changeId}' is in status 'in development'."
return true
} else {
if(configuration.failIfStatusIsNotInDevelopment.toBoolean()) {
throw new AbortException("Change '${changeId}' is not in status 'in development'.")

} else {
echo "[WARNING] Change '${changeId}' is not in status 'in development'. Failing the pipeline has been explicitly disabled."
return false
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion vars/checksPublishResults.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import groovy.transform.Field
*
* @param others document all parameters
*/
def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script
if (script == null)
Expand Down
2 changes: 1 addition & 1 deletion vars/cloudFoundryDeploy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import groovy.transform.Field
@Field Map CONFIG_KEY_COMPATIBILITY = [cloudFoundry: [apiEndpoint: 'cfApiEndpoint', appName:'cfAppName', credentialsId: 'cfCredentialsId', manifest: 'cfManifest', org: 'cfOrg', space: 'cfSpace']]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

Expand Down
4 changes: 2 additions & 2 deletions vars/handlePipelineStepErrors.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import groovy.transform.Field
@Field STEP_NAME = 'handlePipelineStepErrors'


def call(Map parameters = [:], body) {
void call(Map parameters = [:], body) {

def stepParameters = parameters.stepParameters //mandatory
def stepName = parameters.stepName //mandatory
Expand Down Expand Up @@ -40,7 +40,7 @@ FURTHER INFORMATION:
* Source code of library step ${stepName}: https://github.com/SAP/jenkins-library/blob/master/vars/${stepName}.groovy
* Library documentation: https://sap.github.io/jenkins-library/
* Library repository: https://github.com/SAP/jenkins-library
----------------------------------------------------------"""
throw err
} finally {
Expand Down
2 changes: 1 addition & 1 deletion vars/influxWriteData.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import groovy.transform.Field
'artifactVersion'
])

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) {
def script = parameters.script
if (script == null)
Expand Down
2 changes: 1 addition & 1 deletion vars/mavenExecute.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import groovy.transform.Field
'logSuccessfulMavenTransfers'
])

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
final script = parameters.script

Expand Down
2 changes: 1 addition & 1 deletion vars/mtaBuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import groovy.transform.Field
'dockerOptions'
])

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
final script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]

Expand Down
8 changes: 4 additions & 4 deletions vars/neoDeploy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import groovy.transform.Field
'warAction'
])

def call(parameters = [:]) {
void call(parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
Expand Down Expand Up @@ -70,7 +70,7 @@ def call(parameters = [:]) {
parameters.put('neoCredentialsId', credId)
}
// Backward compatibility end

// load default & individual configuration
Map configuration = ConfigurationHelper.newInstance(this)
.loadStepDefaults()
Expand All @@ -81,9 +81,9 @@ def call(parameters = [:]) {
.addIfEmpty('archivePath', script.commonPipelineEnvironment.getMtarFilePath())
.mixin(parameters, PARAMETER_KEYS)
.use()

utils.pushToSWA([
step: STEP_NAME,
step: STEP_NAME,
stepParam1: configuration.deployMode == 'mta'?'mta':'war', // ['mta', 'warParams', 'warPropertiesFile']
stepParam2: configuration.warAction == 'rolling-update'?'blue-green':'standard' // ['deploy', 'deploy-mta', 'rolling-update']
], configuration)
Expand Down
2 changes: 1 addition & 1 deletion vars/newmanExecute.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import groovy.transform.Field
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
def utils = parameters?.juStabUtils ?: new Utils()
Expand Down
2 changes: 1 addition & 1 deletion vars/pipelineExecute.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import groovy.transform.Field
* Load and executes a pipeline from another git repository.
*
*/
def call(Map parameters = [:]) {
void call(Map parameters = [:]) {

node() {

Expand Down
2 changes: 1 addition & 1 deletion vars/pipelineRestartSteps.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import groovy.transform.Field
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS

def call(Map parameters = [:], body) {
void call(Map parameters = [:], body) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
def jenkinsUtils = parameters.jenkinsUtilsStub ?: new JenkinsUtils()
Expand Down
2 changes: 1 addition & 1 deletion vars/pipelineStashFiles.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import groovy.transform.Field

@Field STEP_NAME = 'pipelineStashFiles'

def call(Map parameters = [:], body) {
void call(Map parameters = [:], body) {
handlePipelineStepErrors (stepName: 'pipelineStashFiles', stepParameters: parameters) {
pipelineStashFilesBeforeBuild(parameters)
body() //execute build
Expand Down
2 changes: 1 addition & 1 deletion vars/pipelineStashFilesAfterBuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import groovy.transform.Field
@Field Set STEP_CONFIG_KEYS = ['runCheckmarx', 'stashIncludes', 'stashExcludes']
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, stepNameDoc: 'stashFiles') {
def utils = parameters.juStabUtils
Expand Down
2 changes: 1 addition & 1 deletion vars/pipelineStashFilesBeforeBuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import groovy.transform.Field
@Field Set STEP_CONFIG_KEYS = ['runOpaTests', 'stashIncludes', 'stashExcludes']
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, stepNameDoc: 'stashFiles') {

Expand Down
2 changes: 1 addition & 1 deletion vars/prepareDefaultValues.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import groovy.transform.Field

@Field STEP_NAME = 'prepareDefaultValues'

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: 'prepareDefaultValues', stepParameters: parameters) {
if(!DefaultValueCache.getInstance() || parameters.customDefaults) {
def defaultValues = [:]
Expand Down
2 changes: 1 addition & 1 deletion vars/seleniumExecuteTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import groovy.text.SimpleTemplateEngine
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS

def call(Map parameters = [:], Closure body) {
void call(Map parameters = [:], Closure body) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
def utils = parameters?.juStabUtils ?: new Utils()
Expand Down
2 changes: 1 addition & 1 deletion vars/setupCommonPipelineEnvironment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import groovy.transform.Field
@Field String STEP_NAME = 'setupCommonPipelineEnvironment'
@Field Set GENERAL_CONFIG_KEYS = ['collectTelemetryData']

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

Expand Down
2 changes: 1 addition & 1 deletion vars/snykExecute.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import groovy.transform.Field
])
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def utils = parameters.juStabUtils ?: new Utils()
def script = parameters.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
Expand Down
2 changes: 1 addition & 1 deletion vars/testsPublishResults.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import groovy.transform.Field
* @param script global script environment of the Jenkinsfile run
* @param others document all parameters
*/
def call(Map parameters = [:]) {
void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters.script
if (script == null)
Expand Down
2 changes: 1 addition & 1 deletion vars/toolValidate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import hudson.AbortException

@Field STEP_NAME = 'toolValidate'

def call(Map parameters = [:]) {
void call(Map parameters = [:]) {

handlePipelineStepErrors (stepName: 'toolValidate', stepParameters: parameters) {

Expand Down
7 changes: 4 additions & 3 deletions vars/transportRequestCreate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import hudson.AbortException

def call(parameters = [:]) {

def transportRequestId

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
Expand Down Expand Up @@ -76,8 +78,6 @@ def call(parameters = [:]) {
"Change document id not provided (parameter: \'changeDocumentId\' or via commit history).")
.use()

def transportRequestId

echo "[INFO] Creating transport request for change document '${configuration.changeDocumentId}' and development system '${configuration.developmentSystemId}'."

try {
Expand All @@ -92,6 +92,7 @@ def call(parameters = [:]) {


echo "[INFO] Transport Request '$transportRequestId' has been successfully created."
return transportRequestId
}

return transportRequestId
}
2 changes: 1 addition & 1 deletion vars/transportRequestRelease.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import hudson.AbortException

@Field Set generalConfigurationKeys = stepConfigurationKeys

def call(parameters = [:]) {
void call(parameters = [:]) {

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

Expand Down
2 changes: 1 addition & 1 deletion vars/transportRequestUploadFile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import hudson.AbortException
'filePath',
'transportRequestId'])

def call(parameters = [:]) {
void call(parameters = [:]) {

handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {

Expand Down

0 comments on commit 63dd8f4

Please sign in to comment.