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:
commit
479b1d483a
75
test/groovy/CommonStepsTest.groovy
Normal file
75
test/groovy/CommonStepsTest.groovy
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
import groovy.transform.Field
|
||||||
|
|
||||||
|
@Field STEP_NAME = 'handlePipelineStepErrors'
|
||||||
|
|
||||||
|
|
||||||
def call(Map parameters = [:], body) {
|
def call(Map parameters = [:], body) {
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
@ -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)
|
||||||
|
@ -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) {
|
||||||
|
@ -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++){
|
||||||
|
@ -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 = [:]) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user