From 5642ea8b961979e3d0c7f4de7f5fe218dc471219 Mon Sep 17 00:00:00 2001 From: "aleksandr.vodyanov" Date: Tue, 30 Jan 2024 16:31:08 +0300 Subject: [PATCH] DO-143 code freeze (#11) Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/11 Co-authored-by: aleksandr.vodyanov Co-committed-by: aleksandr.vodyanov --- src/tech/avroid/api/Gitea.groovy | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/tech/avroid/api/Gitea.groovy b/src/tech/avroid/api/Gitea.groovy index 8f402ec..84edd76 100644 --- a/src/tech/avroid/api/Gitea.groovy +++ b/src/tech/avroid/api/Gitea.groovy @@ -43,4 +43,38 @@ class Gitea implements Serializable { return result[res.status.toString()] } + + /** + * create new tag + * @param targetBranch String - target branch + * @param tagName String - tag name + * @param message String - message for tag + * @return Boolean - True success create False - already exists + */ + public Boolean createTag(String targetBranch, String tagName, String message = '') { + Map body = [ + message: message, + tag_name: tagName, + target: targetBranch + ] + + Object bodyRequest = JsonOutput.toJson(body) + + Object res = script.httpRequest( + url: "${projectURL}/tags", + ignoreSslErrors: true, + httpMode: 'POST', + validResponseCodes: '201,409', + authentication: creds, + contentType: 'APPLICATION_JSON', + requestBody: bodyRequest + ) + /* groovylint-disable-next-line DuplicateMapLiteral */ + Map result = [ + '409': false, + '201': true + ] + + return result[res.status.toString()] + } }