Compare commits

..

2 Commits

Author SHA1 Message Date
43a8d8250f BM4 2024-09-12 12:07:37 +03:00
8ddeceb0f9 BM3 2024-09-12 11:03:42 +03:00

54
Jenkinsfile vendored
View File

@ -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'
}
@ -29,7 +43,6 @@ pipeline {
environment {
GIT_SERVER = 'git.onlyoffice.com'
GITEA_TOKEN = credentials('gitea-token')
GITHUB_TOKEN = credentials('github-token')
TELEGRAM_TOKEN = credentials('telegram-bot-token')
}
options {
@ -48,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 (
@ -72,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) {
@ -97,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]
@ -124,7 +137,7 @@ pipeline {
}
}
} else if (params.action_type.startsWith('merge')) {
} else if (params.action_type == 'merge') {
baseBranches = ['master']
@ -141,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())
@ -165,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]
@ -191,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)) {
@ -209,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)
@ -217,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)
@ -376,7 +389,12 @@ def protectBranch(String repo, String branch) {
label: "${repo}: protect ${branch}",
script: """
HTTP_CODE=\$(echo '{
"branch_name": "${branch}"
"branch_name": "${branch}",
"enable_push": true,
"enable_push_whitelist": true,
"push_whitelist_usernames": [
"heatray"
]
}' | \
curl -s -X 'POST' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections' \
@ -412,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