1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Merge remote-tracking branch 'github/master' into HEAD

This commit is contained in:
Marcus Holl 2018-10-11 08:36:18 +02:00
commit 479b1d483a
8 changed files with 101 additions and 1 deletions

View File

@ -0,0 +1,75 @@
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 java.lang.reflect.Field
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import groovy.io.FileType
import util.BasePiperTest
import util.Rules
/*
* Intended for collecting generic checks applied to all steps.
*/
public class CommonStepsTest extends BasePiperTest{
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
@Test
public void stepsWithWrongFieldNameTest() {
def whitelist = ['commonPipelineEnvironment']
def stepsWithWrongStepName = []
for(def step in getSteps()) {
if(whitelist.contains(step)) continue
def script = loadScript("${step}.groovy")
def fields = script.getClass().getDeclaredFields() as Set
Field stepNameField = fields.find { it.getName() == 'STEP_NAME'}
if(! stepNameField) {
stepsWithWrongStepName.add(step)
continue
}
boolean notAccessible = false;
def fieldName
if(!stepNameField.isAccessible()) {
stepNameField.setAccessible(true)
notAccessible = true
}
try {
fieldName = stepNameField.get(script)
} finally {
if(notAccessible) stepNameField.setAccessible(false)
}
if(fieldName != step) {
stepsWithWrongStepName.add(step)
}
}
assertThat("Steps with wrong step name or without STEP_NAME field.: ${stepsWithWrongStepName}",
stepsWithWrongStepName, is(empty()))
}
private static getSteps() {
List steps = []
new File('vars').traverse(type: FileType.FILES, maxDepth: 0)
{ if(it.getName().endsWith('.groovy')) steps << (it =~ /vars\/(.*)\.groovy/)[0][1] }
return steps
}
}

View File

@ -1,3 +1,7 @@
import groovy.transform.Field
@Field STEP_NAME = 'durationMeasure'
def call(Map parameters = [:], body) { def call(Map parameters = [:], body) {
def script = parameters.script def script = parameters.script

View File

@ -1,3 +1,7 @@
import groovy.transform.Field
@Field STEP_NAME = 'handlePipelineStepErrors'
def call(Map parameters = [:], body) { def call(Map parameters = [:], body) {

View File

@ -1,5 +1,11 @@
import com.sap.piper.Utils import com.sap.piper.Utils
import groovy.transform.Field
@Field STEP_NAME = 'pipelineExecute'
/** /**
* pipelineExecute * pipelineExecute
* Load and executes a pipeline from another git repository. * Load and executes a pipeline from another git repository.

View File

@ -1,3 +1,7 @@
import groovy.transform.Field
@Field STEP_NAME = 'pipelineStashFiles'
def call(Map parameters = [:], body) { def call(Map parameters = [:], body) {
handlePipelineStepErrors (stepName: 'pipelineStashFiles', stepParameters: parameters) { handlePipelineStepErrors (stepName: 'pipelineStashFiles', stepParameters: parameters) {
pipelineStashFilesBeforeBuild(parameters) pipelineStashFilesBeforeBuild(parameters)

View File

@ -1,6 +1,10 @@
import com.sap.piper.DefaultValueCache import com.sap.piper.DefaultValueCache
import com.sap.piper.MapUtils import com.sap.piper.MapUtils
import groovy.transform.Field
@Field STEP_NAME = 'prepareDefaultValues'
def call(Map parameters = [:]) { def call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: 'prepareDefaultValues', stepParameters: parameters) { handlePipelineStepErrors (stepName: 'prepareDefaultValues', stepParameters: parameters) {
if(!DefaultValueCache.getInstance() || parameters.customDefaults) { if(!DefaultValueCache.getInstance() || parameters.customDefaults) {

View File

@ -122,7 +122,7 @@ def publishJMeterReport(Map settings = [:]){
} }
} }
def touchFiles(){ void touchFiles(pattern){
echo "[${STEP_NAME}] update test results" echo "[${STEP_NAME}] update test results"
def patternArray = pattern.split(',') def patternArray = pattern.split(',')
for(def i = 0; i < patternArray.length; i++){ for(def i = 0; i < patternArray.length; i++){

View File

@ -3,8 +3,11 @@ 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 hudson.AbortException import hudson.AbortException
@Field STEP_NAME = 'toolValidate'
def call(Map parameters = [:]) { def call(Map parameters = [:]) {