mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-03 15:02:35 +02:00
fix(checkIfStepActive): respect explicit (de-)activation (#3055)
This commit is contained in:
parent
045c72cd3e
commit
5096b3bfe1
@ -28,34 +28,40 @@ func (r *RunConfig) evaluateConditions(config *Config, filters map[string]StepFi
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for conditionName, condition := range stepCondition {
|
||||
var err error
|
||||
switch conditionName {
|
||||
case configCondition:
|
||||
if stepActive, err = checkConfig(condition, stepConfig, stepName); err != nil {
|
||||
return errors.Wrapf(err, "error: check config condition failed")
|
||||
|
||||
if active, ok := stepConfig.Config[stepName].(bool); ok {
|
||||
// respect explicit activation/de-activation if available
|
||||
stepActive = active
|
||||
} else {
|
||||
for conditionName, condition := range stepCondition {
|
||||
var err error
|
||||
switch conditionName {
|
||||
case configCondition:
|
||||
if stepActive, err = checkConfig(condition, stepConfig, stepName); err != nil {
|
||||
return errors.Wrapf(err, "error: check config condition failed")
|
||||
}
|
||||
case configKeysCondition:
|
||||
if stepActive, err = checkConfigKeys(condition, stepConfig, stepName); err != nil {
|
||||
return errors.Wrapf(err, "error: check configKeys condition failed")
|
||||
}
|
||||
case filePatternFromConfigCondition:
|
||||
if stepActive, err = checkForFilesWithPatternFromConfig(condition, stepConfig, stepName, glob); err != nil {
|
||||
return errors.Wrapf(err, "error: check filePatternFromConfig condition failed")
|
||||
}
|
||||
case filePatternCondition:
|
||||
if stepActive, err = checkForFilesWithPattern(condition, stepConfig, stepName, glob); err != nil {
|
||||
return errors.Wrapf(err, "error: check filePattern condition failed")
|
||||
}
|
||||
case npmScriptsCondition:
|
||||
if stepActive, err = checkForNpmScriptsInPackages(condition, stepConfig, stepName, glob, r.OpenFile); err != nil {
|
||||
return errors.Wrapf(err, "error: check npmScripts condition failed")
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unknown condition %s", conditionName)
|
||||
}
|
||||
case configKeysCondition:
|
||||
if stepActive, err = checkConfigKeys(condition, stepConfig, stepName); err != nil {
|
||||
return errors.Wrapf(err, "error: check configKeys condition failed")
|
||||
if stepActive {
|
||||
break
|
||||
}
|
||||
case filePatternFromConfigCondition:
|
||||
if stepActive, err = checkForFilesWithPatternFromConfig(condition, stepConfig, stepName, glob); err != nil {
|
||||
return errors.Wrapf(err, "error: check filePatternFromConfig condition failed")
|
||||
}
|
||||
case filePatternCondition:
|
||||
if stepActive, err = checkForFilesWithPattern(condition, stepConfig, stepName, glob); err != nil {
|
||||
return errors.Wrapf(err, "error: check filePattern condition failed")
|
||||
}
|
||||
case npmScriptsCondition:
|
||||
if stepActive, err = checkForNpmScriptsInPackages(condition, stepConfig, stepName, glob, r.OpenFile); err != nil {
|
||||
return errors.Wrapf(err, "error: check npmScripts condition failed")
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unknown condition %s", conditionName)
|
||||
}
|
||||
if stepActive {
|
||||
break
|
||||
}
|
||||
}
|
||||
runStep[stepName] = stepActive
|
||||
|
@ -501,6 +501,32 @@ stages:
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "test explicit activation / de-activation of step",
|
||||
customConfig: &Config{
|
||||
Stages: map[string]map[string]interface{}{
|
||||
"testStage1": {
|
||||
"firstStep": true,
|
||||
"fisecondStep": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
stageConfig: ioutil.NopCloser(strings.NewReader(`
|
||||
stages:
|
||||
testStage1:
|
||||
stepConditions:
|
||||
firstStep:
|
||||
config: testGeneral
|
||||
secondStep:
|
||||
config: testStage
|
||||
`)),
|
||||
runStepsExpected: map[string]map[string]bool{
|
||||
"testStage1": {
|
||||
"firstStep": true,
|
||||
"secondStep": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user