Compare commits
2 Commits
dfd04e1bf4
...
43a8d8250f
Author | SHA1 | Date | |
---|---|---|---|
43a8d8250f | |||
8ddeceb0f9 |
54
Jenkinsfile
vendored
54
Jenkinsfile
vendored
@ -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'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +43,6 @@ pipeline {
|
|||||||
environment {
|
environment {
|
||||||
GIT_SERVER = 'git.onlyoffice.com'
|
GIT_SERVER = 'git.onlyoffice.com'
|
||||||
GITEA_TOKEN = credentials('gitea-token')
|
GITEA_TOKEN = credentials('gitea-token')
|
||||||
GITHUB_TOKEN = credentials('github-token')
|
|
||||||
TELEGRAM_TOKEN = credentials('telegram-bot-token')
|
TELEGRAM_TOKEN = credentials('telegram-bot-token')
|
||||||
}
|
}
|
||||||
options {
|
options {
|
||||||
@ -48,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 (
|
||||||
@ -72,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) {
|
||||||
@ -97,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]
|
||||||
@ -124,7 +137,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (params.action_type.startsWith('merge')) {
|
} else if (params.action_type == 'merge') {
|
||||||
|
|
||||||
baseBranches = ['master']
|
baseBranches = ['master']
|
||||||
|
|
||||||
@ -141,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())
|
||||||
@ -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
|
branch = defaults.branch_type + '/v' + params.version
|
||||||
baseBranches = [env.BRANCH_NAME]
|
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 ->
|
stats.repos.each { repo, status ->
|
||||||
if (!checkRemoteBranch(repo, branch)) {
|
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 ->
|
stats.repos.each { repo, status ->
|
||||||
pAction = protectBranch(repo, branch)
|
pAction = protectBranch(repo, branch)
|
||||||
@ -217,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)
|
||||||
@ -376,7 +389,12 @@ def protectBranch(String repo, String branch) {
|
|||||||
label: "${repo}: protect ${branch}",
|
label: "${repo}: protect ${branch}",
|
||||||
script: """
|
script: """
|
||||||
HTTP_CODE=\$(echo '{
|
HTTP_CODE=\$(echo '{
|
||||||
"branch_name": "${branch}"
|
"branch_name": "${branch}",
|
||||||
|
"enable_push": true,
|
||||||
|
"enable_push_whitelist": true,
|
||||||
|
"push_whitelist_usernames": [
|
||||||
|
"heatray"
|
||||||
|
]
|
||||||
}' | \
|
}' | \
|
||||||
curl -s -X 'POST' \
|
curl -s -X 'POST' \
|
||||||
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections' \
|
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections' \
|
||||||
@ -412,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
|
||||||
|
Loading…
Reference in New Issue
Block a user