From 43a8d8250fde32c042444e3cbb0d47c31e903629 Mon Sep 17 00:00:00 2001 From: Semyon Bezrukov Date: Thu, 12 Sep 2024 12:07:37 +0300 Subject: [PATCH] BM4 --- Jenkinsfile | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4cbff3e..3368a67 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,19 +6,33 @@ defaults = [ ] if (env.BRANCH_NAME == 'master') { - defaults.action_type.add('start_hotfix') + defaults.action_type.add('start') + defaults.action_type.add('protect') + defaults.action_type.add('unprotect') defaults.branch_type = 'hotfix' } if (env.BRANCH_NAME == 'develop') { - defaults.action_type.add('start_release') + defaults.action_type.add('start') + defaults.action_type.add('protect') + defaults.action_type.add('unprotect') defaults.branch_type = 'release' } if (env.BRANCH_NAME ==~ /^(hotfix)\/.+/) { - defaults.action_type.addAll(['merge_hotfix', 'finish_hotfix', 'rename_hotfix', 'delete_hotfix', 'protect_hotfix', 'unprotect_hotfix']) + defaults.action_type.add('merge') + defaults.action_type.add('finish') + defaults.action_type.add('rename') + defaults.action_type.add('delete') + defaults.action_type.add('protect') + defaults.action_type.add('unprotect') defaults.branch_type = 'hotfix' } if (env.BRANCH_NAME ==~ /^(release)\/.+/) { - defaults.action_type.addAll(['merge_release', 'finish_release', 'rename_release', 'delete_release', 'protect_release', 'unprotect_release']) + defaults.action_type.add('merge') + defaults.action_type.add('finish') + defaults.action_type.add('rename') + defaults.action_type.add('delete') + defaults.action_type.add('protect') + defaults.action_type.add('unprotect') defaults.branch_type = 'release' } @@ -47,7 +61,7 @@ pipeline { ) string ( name: 'version', - description: 'Release version (for start only)', + description: 'Release version (for start only) [' + defaults.branch_type + ']', defaultValue: defaults.version ) booleanParam ( @@ -71,7 +85,7 @@ pipeline { steps { script { currentBuild.displayName += ' - ' + params.action_type - if (params.action_type in ['start_hotfix', 'start_release']) + if (params.action_type == 'start') currentBuild.displayName += ' ' + params.version if (params.wipe) { @@ -96,7 +110,7 @@ pipeline { status.secondary = 'none' } - } else if (params.action_type.startsWith('start')) { + } else if (params.action_type == 'start') { branch = defaults.branch_type + '/v' + params.version baseBranches = [env.BRANCH_NAME] @@ -123,7 +137,7 @@ pipeline { } } - } else if (params.action_type.startsWith('merge')) { + } else if (params.action_type == 'merge') { baseBranches = ['master'] @@ -140,7 +154,7 @@ pipeline { } } - } else if (params.action_type.startsWith('finish')) { + } else if (params.action_type == 'finish') { baseBranches = ['master', 'develop'] if (!params.extra_branch.isEmpty()) @@ -164,7 +178,7 @@ pipeline { } } - } else if (params.action_type.startsWith('rename')) { + } else if (params.action_type == 'rename') { branch = defaults.branch_type + '/v' + params.version baseBranches = [env.BRANCH_NAME] @@ -190,7 +204,7 @@ pipeline { } } - } else if (params.action_type.startsWith('delete')) { + } else if (params.action_type == 'delete') { stats.repos.each { repo, status -> if (!checkRemoteBranch(repo, branch)) { @@ -208,7 +222,7 @@ pipeline { } } - } else if (params.action_type.startsWith('protect')) { + } else if (params.action_type == 'protect') { stats.repos.each { repo, status -> pAction = protectBranch(repo, branch) @@ -216,7 +230,7 @@ pipeline { status.secondary = 'none' } - } else if (params.action_type.startsWith('unprotect')) { + } else if (params.action_type == 'unprotect') { stats.repos.each { repo, status -> pAction = unprotectBranch(repo, branch) @@ -416,13 +430,13 @@ def unprotectBranch(String repo, String branch) { def sendNotification() { String text = '' switch(params.action_type) { - case ['start_hotfix', 'start_release']: + case 'start': text = "Branch `${stats.branch}` created from `${stats.baseBranches[0]}`" break - case ['merge_hotfix', 'merge_release']: + case 'merge': text = "Branch `${stats.branch}` merged into `${stats.baseBranches[0]}`" break - case ['finish_hotfix', 'finish_release']: + case 'finish': text = "Branch `${stats.branch}` merged into " text += stats.baseBranches.collect({"`$it`"}).join(', ') break