diff --git a/Jenkinsfile b/Jenkinsfile index 4cbff3e..83c44b9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,21 +5,24 @@ defaults = [ protect_branch: true ] -if (env.BRANCH_NAME == 'master') { - defaults.action_type.add('start_hotfix') +if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME ==~ /^hotfix\/.+/) { defaults.branch_type = 'hotfix' } -if (env.BRANCH_NAME == 'develop') { - defaults.action_type.add('start_release') +if (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME ==~ /^release\/.+/) { 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.branch_type = 'hotfix' +if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'develop') { + defaults.action_type.add('start') + defaults.action_type.add('protect') + defaults.action_type.add('unprotect') } -if (env.BRANCH_NAME ==~ /^(release)\/.+/) { - defaults.action_type.addAll(['merge_release', 'finish_release', 'rename_release', 'delete_release', 'protect_release', 'unprotect_release']) - defaults.branch_type = 'release' +if (env.BRANCH_NAME ==~ /^(hotfix)\/.+/ || env.BRANCH_NAME ==~ /^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') } pipeline { @@ -47,7 +50,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 +74,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 +99,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 +126,7 @@ pipeline { } } - } else if (params.action_type.startsWith('merge')) { + } else if (params.action_type == 'merge') { baseBranches = ['master'] @@ -140,7 +143,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 +167,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 +193,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 +211,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 +219,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 +419,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