diff --git a/Jenkinsfile b/Jenkinsfile index 4841b08..f96bfc2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -94,6 +94,7 @@ pipeline { stats.repos.each { repo, status -> pAction = printBranches(repo) status.primary = (pAction) ? 'success' : 'failure' + status.secondary = 'none' } } else if (params.action_type.startsWith('start')) { @@ -358,11 +359,13 @@ def printBranches(String repo) { return sh ( label: "${repo}: branches list", script: """ - curl -sv -f -X 'GET' \ + 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}' \ + -o output.json) + test \$HTTP_CODE -eq 200 + jq -r '.[] | [.name, .protected] | @tsv' output.json """, returnStatus: true ) == 0 @@ -373,13 +376,11 @@ def protectBranch(String repo, String branch) { label: "${repo}: protect ${branch}", script: """ echo '{ - "branch_name": "master" + "branch_name": "${branch}" }' | \ - curl -sv -f -X 'POST' \ + curl -s -X 'POST' \ 'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections' \ - -H 'accept: application/json' \ - -H 'Authorization: '"\$GITEA_TOKEN" \ - -H 'Content-Type: application/json' \ + -H 'Authorization: token '"\$GITEA_TOKEN" \ -d @- """, returnStatus: true @@ -387,13 +388,13 @@ 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 -sv -f -X 'DELETE' \ - 'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections/${branch}' \ - -H 'accept: application/json' \ - -H 'Authorization: '"\$GITEA_TOKEN" + curl -s -X 'DELETE' \ + 'https://'"\$GIT_SERVER"'/api/v1/repos/${repo}/branch_protections/${branchUrl}' \ + -H 'Authorization: token '"\$GITEA_TOKEN" """, returnStatus: true ) == 0