diff --git a/src/vn/fireflylab/pipeline/BranchStrategy.groovy b/src/vn/fireflylab/pipeline/BranchStrategy.groovy index 2410d11..6d2a460 100644 --- a/src/vn/fireflylab/pipeline/BranchStrategy.groovy +++ b/src/vn/fireflylab/pipeline/BranchStrategy.groovy @@ -9,15 +9,8 @@ class BranchStrategy implements Serializable { static boolean isRelease(String branch) { branch ==~ /^release\/\d+\.\d+\.\d+$/ } static boolean isHotfix(String branch) { branch ==~ /^hotfix\/.+/ } - // Build + push on all branches except PRs - static boolean shouldBuildImage(String branch) { - return !isPR(branch) - } - - // Helm bump + git commit/push only on feature branches - static boolean shouldBumpChart(String branch) { - return false - } + static boolean shouldBuildImage(String branch) { return !isPR(branch) } + static boolean shouldBumpChart(String branch) { return false } static String imageTag(String branch) { if (isRelease(branch)) return branch.replaceFirst('release/', '') @@ -25,7 +18,14 @@ class BranchStrategy implements Serializable { if (isMain(branch)) return "main-${shortId}" if (isDevelop(branch)) return "dev-${shortId}" if (isHotfix(branch)) return "hotfix-${shortId}" - // feature/* and anything else: sanitize branch name + random suffix return "${branch.replaceAll('[^a-zA-Z0-9._-]', '-')}-${shortId}" } + + // Strategy methods — execute body only when branch matches + static void prStrategy(String branch, Closure body) { if (isPR(branch)) body() } + static void featureStrategy(String branch, Closure body) { if (isFeature(branch)) body() } + static void developStrategy(String branch, Closure body) { if (isDevelop(branch)) body() } + static void mainStrategy(String branch, Closure body) { if (isMain(branch)) body() } + static void releaseStrategy(String branch, Closure body) { if (isRelease(branch)) body() } + static void hotfixStrategy(String branch, Closure body) { if (isHotfix(branch)) body() } }