This commit is contained in:
Semyon Bezrukov 2024-09-12 12:07:37 +03:00
parent 8ddeceb0f9
commit 43a8d8250f

46
Jenkinsfile vendored
View File

@ -6,19 +6,33 @@ defaults = [
] ]
if (env.BRANCH_NAME == 'master') { 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' defaults.branch_type = 'hotfix'
} }
if (env.BRANCH_NAME == 'develop') { 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' defaults.branch_type = 'release'
} }
if (env.BRANCH_NAME ==~ /^(hotfix)\/.+/) { 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' defaults.branch_type = 'hotfix'
} }
if (env.BRANCH_NAME ==~ /^(release)\/.+/) { 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' defaults.branch_type = 'release'
} }
@ -47,7 +61,7 @@ pipeline {
) )
string ( string (
name: 'version', name: 'version',
description: 'Release version (for start only)', description: 'Release version (for start only) [' + defaults.branch_type + ']',
defaultValue: defaults.version defaultValue: defaults.version
) )
booleanParam ( booleanParam (
@ -71,7 +85,7 @@ pipeline {
steps { steps {
script { script {
currentBuild.displayName += ' - ' + params.action_type currentBuild.displayName += ' - ' + params.action_type
if (params.action_type in ['start_hotfix', 'start_release']) if (params.action_type == 'start')
currentBuild.displayName += ' ' + params.version currentBuild.displayName += ' ' + params.version
if (params.wipe) { if (params.wipe) {
@ -96,7 +110,7 @@ pipeline {
status.secondary = 'none' status.secondary = 'none'
} }
} else if (params.action_type.startsWith('start')) { } else if (params.action_type == 'start') {
branch = defaults.branch_type + '/v' + params.version branch = defaults.branch_type + '/v' + params.version
baseBranches = [env.BRANCH_NAME] baseBranches = [env.BRANCH_NAME]
@ -123,7 +137,7 @@ pipeline {
} }
} }
} else if (params.action_type.startsWith('merge')) { } else if (params.action_type == 'merge') {
baseBranches = ['master'] baseBranches = ['master']
@ -140,7 +154,7 @@ pipeline {
} }
} }
} else if (params.action_type.startsWith('finish')) { } else if (params.action_type == 'finish') {
baseBranches = ['master', 'develop'] baseBranches = ['master', 'develop']
if (!params.extra_branch.isEmpty()) 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 branch = defaults.branch_type + '/v' + params.version
baseBranches = [env.BRANCH_NAME] 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 -> stats.repos.each { repo, status ->
if (!checkRemoteBranch(repo, branch)) { 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 -> stats.repos.each { repo, status ->
pAction = protectBranch(repo, branch) pAction = protectBranch(repo, branch)
@ -216,7 +230,7 @@ pipeline {
status.secondary = 'none' status.secondary = 'none'
} }
} else if (params.action_type.startsWith('unprotect')) { } else if (params.action_type == 'unprotect') {
stats.repos.each { repo, status -> stats.repos.each { repo, status ->
pAction = unprotectBranch(repo, branch) pAction = unprotectBranch(repo, branch)
@ -416,13 +430,13 @@ def unprotectBranch(String repo, String branch) {
def sendNotification() { def sendNotification() {
String text = '' String text = ''
switch(params.action_type) { switch(params.action_type) {
case ['start_hotfix', 'start_release']: case 'start':
text = "Branch `${stats.branch}` created from `${stats.baseBranches[0]}`" text = "Branch `${stats.branch}` created from `${stats.baseBranches[0]}`"
break break
case ['merge_hotfix', 'merge_release']: case 'merge':
text = "Branch `${stats.branch}` merged into `${stats.baseBranches[0]}`" text = "Branch `${stats.branch}` merged into `${stats.baseBranches[0]}`"
break break
case ['finish_hotfix', 'finish_release']: case 'finish':
text = "Branch `${stats.branch}` merged into " text = "Branch `${stats.branch}` merged into "
text += stats.baseBranches.collect({"`$it`"}).join(', ') text += stats.baseBranches.collect({"`$it`"}).join(', ')
break break