mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
fix(checkIfStepActive): nested key logic (#3939)
* fix(checkIfStepActive): nested key logic Co-authored-by: Raman Susla <raman_susla@epam.com> Co-authored-by: Ashly Mathew <ashly.mathew@sap.com>
This commit is contained in:
parent
c81e741224
commit
374cdb777b
@ -125,10 +125,8 @@ func (s *StepCondition) evaluateV1(config StepConfig, utils piperutils.FileUtils
|
||||
}
|
||||
|
||||
if len(s.ConfigKey) > 0 {
|
||||
if configValue := config.Config[s.ConfigKey]; configValue != nil {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
configKey := strings.Split(s.ConfigKey, "/")
|
||||
return checkConfigKeyV1(config.Config, configKey)
|
||||
}
|
||||
|
||||
if len(s.FilePattern) > 0 {
|
||||
@ -194,6 +192,18 @@ func (s *StepCondition) evaluateV1(config StepConfig, utils piperutils.FileUtils
|
||||
}
|
||||
}
|
||||
|
||||
func checkConfigKeyV1(config map[string]interface{}, configKey []string) (bool, error) {
|
||||
value, ok := config[configKey[0]]
|
||||
if len(configKey) == 1 {
|
||||
return ok, nil
|
||||
}
|
||||
castedValue, ok := value.(map[string]interface{})
|
||||
if !ok {
|
||||
return false, nil
|
||||
}
|
||||
return checkConfigKeyV1(castedValue, configKey[1:])
|
||||
}
|
||||
|
||||
// EvaluateConditions validates stage conditions and updates runSteps in runConfig
|
||||
func (r *RunConfig) evaluateConditions(config *Config, filters map[string]StepFilters, parameters map[string][]StepParameters,
|
||||
secrets map[string][]StepSecrets, stepAliases map[string][]Alias, glob func(pattern string) (matches []string, err error)) error {
|
||||
|
@ -72,6 +72,12 @@ func TestEvaluateConditionsV1(t *testing.T) {
|
||||
Name: "step1_3",
|
||||
Conditions: []StepCondition{},
|
||||
},
|
||||
{
|
||||
Name: "step1_4",
|
||||
Conditions: []StepCondition{
|
||||
{ConfigKey: "firstKey/nextKey"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -108,7 +114,7 @@ func TestEvaluateConditionsV1(t *testing.T) {
|
||||
},
|
||||
}
|
||||
config := Config{Stages: map[string]map[string]interface{}{
|
||||
"Test Stage 1": {"step1_3": false, "testKey": "testVal"},
|
||||
"Test Stage 1": {"step1_3": false, "testKey": "testVal", "firstKey": map[string]interface{}{"nextKey": "dummy"}},
|
||||
"Test Stage 2": {"testKey": "testVal"},
|
||||
}}
|
||||
|
||||
@ -116,6 +122,7 @@ func TestEvaluateConditionsV1(t *testing.T) {
|
||||
"Test Stage 1": {
|
||||
"step1_2": true,
|
||||
"step1_3": false,
|
||||
"step1_4": true,
|
||||
},
|
||||
"Test Stage 2": {
|
||||
"step2_1": true,
|
||||
@ -289,6 +296,22 @@ func TestEvaluateV1(t *testing.T) {
|
||||
stepCondition: StepCondition{ConfigKey: "dockerRegistryUrl"},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "nested ConfigKey condition - true",
|
||||
config: StepConfig{Config: map[string]interface{}{
|
||||
"cloudFoundry": map[string]interface{}{"space": "dev"},
|
||||
}},
|
||||
stepCondition: StepCondition{ConfigKey: "cloudFoundry/space"},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "nested ConfigKey condition - false",
|
||||
config: StepConfig{Config: map[string]interface{}{
|
||||
"cloudFoundry": map[string]interface{}{"noSpace": "dev"},
|
||||
}},
|
||||
stepCondition: StepCondition{ConfigKey: "cloudFoundry/space"},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "FilePattern condition - true",
|
||||
config: StepConfig{Config: map[string]interface{}{}},
|
||||
|
Loading…
x
Reference in New Issue
Block a user