From f08e80f131e85a97df2f1863a9fc508ba4690a2f Mon Sep 17 00:00:00 2001 From: Semyon Bezrukov Date: Wed, 11 Sep 2024 16:38:58 +0300 Subject: [PATCH] BM2 --- Jenkinsfile | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1e2992d..4841b08 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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,10 +358,10 @@ def printBranches(String repo) { return sh ( label: "${repo}: branches list", script: """ - curl -X 'GET' \ - 'https://\$GIT_SERVER/api/v1/repos/${repo}/branches' \ + curl -sv -f -X 'GET' \ + 'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branches' \ -H 'accept: application/json' \ - -H 'Authorization: \$GITEA_TOKEN' | \ + -H 'Authorization: '"\$GITEA_TOKEN" | \ jq -r '.[] | [.name, .protected] | @tsv' """, returnStatus: true @@ -375,12 +375,12 @@ def protectBranch(String repo, String branch) { echo '{ "branch_name": "master" }' | \ - curl -X 'POST' \ - 'https://\$GIT_SERVER/api/v1/repos/${repo}/branch_protections?token=\$GITEA_TOKEN' \ + curl -sv -f -X 'POST' \ + 'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections' \ -H 'accept: application/json' \ - -H 'Authorization: \$GITEA_TOKEN' \ + -H 'Authorization: '"\$GITEA_TOKEN" \ -H 'Content-Type: application/json' \ - -d - + -d @- """, returnStatus: true ) == 0 @@ -390,11 +390,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 -sv -f -X 'DELETE' \ + 'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections/${branch}' \ -H 'accept: application/json' \ - -H 'Authorization: \$GITEA_TOKEN' - """ + -H 'Authorization: '"\$GITEA_TOKEN" + """, returnStatus: true ) == 0 }