Compare commits

...

7 Commits

Author SHA1 Message Date
d67feb347c BM8 2024-09-11 18:01:22 +03:00
bbe929fce2 BM7 2024-09-11 17:48:29 +03:00
74276d0c45 BM6 2024-09-11 17:45:44 +03:00
59752f6b7a BM5 2024-09-11 17:42:14 +03:00
180496fde6 BM4 2024-09-11 17:37:33 +03:00
7247dbe4a4 BM3 2024-09-11 17:35:30 +03:00
f08e80f131 BM2 2024-09-11 17:29:39 +03:00

52
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'
}
@ -96,7 +96,7 @@ pipeline {
status.primary = (pAction) ? 'success' : 'failure'
}
} else if params.action_type.startsWith('start') {
} else if (params.action_type.startsWith('start')) {
branch = defaults.branch_type + '/v' + params.version
baseBranches = [env.BRANCH_NAME]
@ -117,13 +117,13 @@ pipeline {
}
}
if (params.protect_branch) {
if (params.protect_branch && !repo.contains('documents-pipeline')) {
sAction = protectBranch(repo, branch)
status.secondary = (sAction) ? 'lock' : ''
}
}
} else if params.action_type.startsWith('merge') {
} else if (params.action_type.startsWith('merge')) {
baseBranches = ['master']
@ -140,7 +140,7 @@ pipeline {
}
}
} else if params.action_type.startsWith('finish') {
} else if (params.action_type.startsWith('finish')) {
baseBranches = ['master', 'develop']
if (!params.extra_branch.isEmpty())
@ -164,7 +164,7 @@ pipeline {
}
}
} else if params.action_type.startsWith('rename') {
} else if (params.action_type.startsWith('rename')) {
branch = defaults.branch_type + '/v' + params.version
baseBranches = [env.BRANCH_NAME]
@ -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' : ''
}
@ -190,7 +190,7 @@ pipeline {
}
}
} else if params.action_type.startsWith('delete') {
} else if (params.action_type.startsWith('delete')) {
stats.repos.each { repo, status ->
if (!checkRemoteBranch(repo, branch)) {
@ -208,7 +208,7 @@ pipeline {
}
}
} else if params.action_type.startsWith('protect') {
} else if (params.action_type.startsWith('protect')) {
stats.repos.each { repo, status ->
pAction = protectBranch(repo, branch)
@ -216,7 +216,7 @@ pipeline {
status.secondary = 'none'
}
} else if params.action_type.startsWith('unprotect') {
} else if (params.action_type.startsWith('unprotect')) {
stats.repos.each { repo, status ->
pAction = unprotectBranch(repo, branch)
@ -358,11 +358,15 @@ def printBranches(String repo) {
return sh (
label: "${repo}: branches list",
script: """
curl -X 'GET' \
'https://\$GIT_SERVER/api/v1/repos/${repo}/branches' \
HTTP_CODE=\$(curl -s -X 'GET' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branches' \
-H 'accept: application/json' \
-H 'Authorization: \$GITEA_TOKEN' | \
jq -r '.[] | [.name, .protected] | @tsv'
-H 'Authorization: '"\$GITEA_TOKEN"
-w "%{http_code}\n"
-o output.json)
echo \$HTTP_CODE
cat output.json
jq -r '.[] | [.name, .protected] | @tsv' output.json
""",
returnStatus: true
) == 0
@ -373,14 +377,14 @@ def protectBranch(String repo, String branch) {
label: "${repo}: protect ${branch}",
script: """
echo '{
"branch_name": "master"
"branch_name": "${branch}"
}' | \
curl -X 'POST' \
'https://\$GIT_SERVER/api/v1/repos/${repo}/branch_protections?token=\$GITEA_TOKEN' \
curl -s -X 'POST' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections' \
-H 'accept: application/json' \
-H 'Authorization: \$GITEA_TOKEN' \
-H 'Authorization: token '"\$GITEA_TOKEN" \
-H 'Content-Type: application/json' \
-d -
-d @-
""",
returnStatus: true
) == 0
@ -390,11 +394,11 @@ def unprotectBranch(String repo, String branch) {
return sh (
label: "${repo}: unprotect ${branch}",
script: """
curl -X 'DELETE' \
'https://\$GIT_SERVER/api/v1/repos/${repo}/branch_protections/${branch}?token=\$GITEA_TOKEN' \
curl -s -X 'DELETE' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections/${URLEncoder.encode(branch)}' \
-H 'accept: application/json' \
-H 'Authorization: \$GITEA_TOKEN'
"""
-H 'Authorization: token '"\$GITEA_TOKEN"
""",
returnStatus: true
) == 0
}