diff --git a/gitea.jenkinsfile b/gitea.jenkinsfile new file mode 100644 index 0000000..18f59b6 --- /dev/null +++ b/gitea.jenkinsfile @@ -0,0 +1,99 @@ +pipeline { + agent { + label 'branch_manager' + } + environment { + GIT_SERVER = 'git.onlyoffice.com' + GIT_OWNER = 'ONLYOFFICE' + GITEA_TOKEN = credentials('gitea-token') + } + options { + disableConcurrentBuilds() + } + stages { + stage('Branch Manager') { + steps { + script { + stats = [repos: [:]] + String branch = env.BRANCH_NAME + ArrayList baseBranches = [] + getRepos().each { + stats.repos.put(it, [:]) + } + Boolean pAction + Boolean sAction + + // printBranches + stats.repos.each { repo, status -> + pAction = printBranches(repo) + status.primary = (pAction) ? 'success' : 'failure' + } + + stats.putAll([ + branch: branch, + baseBranches: baseBranches, + success: stats.repos.findAll { repo, status -> + status.primary in ['skip', 'success'] + }.size(), + total: stats.repos.size() + ]) + println stats + + String text = '' + text += "${stats.success}/${stats.total}" + stats.repos.each { repo, status -> + text += '\n' + switch(status.primary) { + case 'skip': text += '🔘'; break + case 'success': text += '☑️'; break + case 'failure': text += '🚫'; break + default: text += '➖' + } + text += " ${repo}" + } + + echo text + } + } + } + } +} + +def getRepos() { + return [ + 'build_tools', + 'core', + 'desktop-apps', + 'desktop-sdk', + 'document-builder-package', + 'document-server-package', + 'documents-pipeline', + 'onlyoffice', + 'sdkjs', + 'sdkjs-forms', + 'sdkjs-ooxml', + 'server', + 'server-license', + 'server-lockstorage', + 'web-apps', + 'web-apps-mobile', + 'Docker-DocumentServer', + 'DocumentBuilder' + ] +} + +def printBranches(String repo) { + return sh ( + label: "${repo}: branches list", + script: """ + HTTP_CODE=\$(curl -s -X 'GET' \ + https://\$GIT_SERVER/api/v1/repos/\$GIT_OWNER/${repo}/branches \ + -H 'Authorization: token '\$GITEA_TOKEN \ + -w %{http_code} \ + -o output.json) + test \$HTTP_CODE -eq 200 + jq -r '.[] | [.name, .protected] | @tsv' output.json + """, + returnStatus: true + ) == 0 +}