From b86e7814e46cd0eb9f9d1724c3a53017742d2c2b Mon Sep 17 00:00:00 2001 From: Aleksandr Vodyanov Date: Thu, 28 Sep 2023 11:47:50 +0000 Subject: [PATCH] DO-75/add_getBranch_method (#4) add getBranch method --- src/tech/avroid/scm/Git.groovy | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/tech/avroid/scm/Git.groovy b/src/tech/avroid/scm/Git.groovy index abd6907..069a95a 100644 --- a/src/tech/avroid/scm/Git.groovy +++ b/src/tech/avroid/scm/Git.groovy @@ -11,6 +11,17 @@ class Git implements Serializable { this.script = script } + * get current Branch name + * @return String - branch name + */ + public String getBranch() { + if (script.env.BRANCH_NAME.startsWith('PR')) { + return "${script.env.CHANGE_BRANCH}" + } + + return "${script.env.BRANCH_NAME}" + } + /** * Method to clone a Git repository * @param args Map - Arguments for cloning