This commit is contained in:
Semyon Bezrukov 2024-09-11 16:47:28 +03:00
parent e23714bdc7
commit 4a3633f9d8

14
Jenkinsfile vendored
View File

@ -14,11 +14,11 @@ if (env.BRANCH_NAME == 'develop') {
defaults.branch_type = 'release'
}
if (env.BRANCH_NAME ==~ /^(hotfix)\/.+/) {
defaults.action_type.addAll(['merge_hotfix', 'finish_hotfix', 'rename_hotfix', 'delete_hotfix', 'unprotect_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 ==~ /^(release)\/.+/) {
defaults.action_type.addAll(['merge_release', 'finish_release', 'rename_release', 'delete_release', 'unprotect_release'])
defaults.action_type.addAll(['merge_release', 'finish_release', 'rename_release', 'delete_release', 'protect_release', 'unprotect_release'])
defaults.branch_type = 'release'
}
@ -117,7 +117,7 @@ pipeline {
}
}
if (params.protect_branch) {
if (params.protect_branch && !repo.contains('documents-pipeline')) {
sAction = protectBranch(repo, branch)
status.secondary = (sAction) ? 'lock' : ''
}
@ -181,7 +181,7 @@ pipeline {
if (pAction) {
unprotectBranch(repo, env.BRANCH_NAME)
deleteBranch(repo, env.BRANCH_NAME)
if (params.protect_branch) {
if (params.protect_branch && !repo.contains('documents-pipeline')) {
sAction = protectBranch(repo, branch)
status.secondary = (sAction) ? 'lock' : ''
}
@ -359,7 +359,7 @@ def printBranches(String repo) {
label: "${repo}: branches list",
script: """
curl -X 'GET' \
'https://\$GIT_SERVER/api/v1/repos/${repo}/branches' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branches' \
-H 'accept: application/json' \
-H 'Authorization: \$GITEA_TOKEN' | \
jq -r '.[] | [.name, .protected] | @tsv'
@ -376,7 +376,7 @@ def protectBranch(String repo, String branch) {
"branch_name": "master"
}' | \
curl -X 'POST' \
'https://\$GIT_SERVER/api/v1/repos/${repo}/branch_protections?token=\$GITEA_TOKEN' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections?token=\$GITEA_TOKEN' \
-H 'accept: application/json' \
-H 'Authorization: \$GITEA_TOKEN' \
-H 'Content-Type: application/json' \
@ -391,7 +391,7 @@ def unprotectBranch(String repo, String branch) {
label: "${repo}: unprotect ${branch}",
script: """
curl -X 'DELETE' \
'https://\$GIT_SERVER/api/v1/repos/${repo}/branch_protections/${branch}?token=\$GITEA_TOKEN' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections/${branch}?token=\$GITEA_TOKEN' \
-H 'accept: application/json' \
-H 'Authorization: \$GITEA_TOKEN'
""",