Skip to content

Commit

Permalink
fix(Central Build): Fix handling legacy stage name for Jenkins pipeli…
Browse files Browse the repository at this point in the history
…nes (#5151)

* add handle stageName

* some improvements

---------

Co-authored-by: maxcask <[email protected]>
Co-authored-by: Googlom <[email protected]>
Co-authored-by: Googlom <[email protected]>
  • Loading branch information
4 people authored Oct 21, 2024
1 parent 769067e commit 4eb1756
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/config/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/pkg/errors"

"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/orchestrator"
"github.com/SAP/jenkins-library/pkg/piperutils"
)
Expand Down Expand Up @@ -39,6 +40,9 @@ func (r *RunConfigV1) evaluateConditionsV1(config *Config, utils piperutils.File
// to also consider using the technical name.
stageName := stage.DisplayName

// Central Build in Jenkins was renamed to Build.
handleLegacyStageNaming(config, currentOrchestrator, stageName)

// Check #1: Apply explicit activation/deactivation from config file (if any)
// and then evaluate stepActive conditions
runStep := make(map[string]bool, len(stage.Steps))
Expand Down Expand Up @@ -305,3 +309,23 @@ func anyOtherStepIsActive(targetStep string, runSteps map[string]bool) bool {

return false
}

func handleLegacyStageNaming(c *Config, orchestrator, stageName string) {
if orchestrator == "Jenkins" && stageName == "Build" {
_, buildExists := c.Stages["Build"]
centralBuildStageConfig, centralBuildExists := c.Stages["Central Build"]
if buildExists && centralBuildExists {
log.Entry().Warnf("You have 2 entries for build stage in config.yml. " +
"Parameters defined under 'Central Build' are ignored. " +
"Please use only 'Build'")
return
}

if centralBuildExists {
c.Stages["Build"] = centralBuildStageConfig
log.Entry().Warnf("You are using 'Central Build' stage in config.yml. " +
"Please move parameters under the 'Build' stage, " +
"since 'Central Build' will be removed in future releases")
}
}
}

0 comments on commit 4eb1756

Please sign in to comment.