This commit is contained in:
Semyon Bezrukov 2024-09-11 18:18:44 +03:00
parent d436c80797
commit 5aaad48a04

10
Jenkinsfile vendored
View File

@ -361,12 +361,10 @@ def printBranches(String repo) {
script: """
HTTP_CODE=\$(curl -s -X 'GET' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branches' \
-H 'accept: application/json' \
-H 'Authorization: '"\$GITEA_TOKEN" \
-w '%{http_code}' \
-o output.json)
echo \$HTTP_CODE
cat output.json
test $HTTP_CODE -eq 200
jq -r '.[] | [.name, .protected] | @tsv' output.json
""",
returnStatus: true
@ -382,9 +380,7 @@ def protectBranch(String repo, String branch) {
}' | \
curl -s -X 'POST' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections' \
-H 'accept: application/json' \
-H 'Authorization: token '"\$GITEA_TOKEN" \
-H 'Content-Type: application/json' \
-d @-
""",
returnStatus: true
@ -392,12 +388,12 @@ def protectBranch(String repo, String branch) {
}
def unprotectBranch(String repo, String branch) {
String branchUrl = URLEncoder.encode(branch)
return sh (
label: "${repo}: unprotect ${branch}",
script: """
curl -s -X 'DELETE' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections/${URLEncoder.encode(branch)}' \
-H 'accept: application/json' \
'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections/${branchUrl}' \
-H 'Authorization: token '"\$GITEA_TOKEN"
""",
returnStatus: true