From bc24016ef4f0de4f71ea02891dbc131bb5392024 Mon Sep 17 00:00:00 2001 From: "aleksandr.vodyanov" Date: Tue, 20 Feb 2024 18:20:53 +0300 Subject: [PATCH] [DO-273] shared libs update (#12) Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/12 Co-authored-by: aleksandr.vodyanov Co-committed-by: aleksandr.vodyanov --- src/tech/avroid/api/Nexus.groovy | 38 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/tech/avroid/api/Nexus.groovy b/src/tech/avroid/api/Nexus.groovy index 8bf9c5b..f214c39 100644 --- a/src/tech/avroid/api/Nexus.groovy +++ b/src/tech/avroid/api/Nexus.groovy @@ -8,9 +8,9 @@ class Nexus implements Serializable { /** * - @param script Script - context pointer on step in Pipelines - @param host String - Nexus host name - @param credentials String - User's name and pass in Nexus + @param script Script - context pointer on step in Pipelines + @param host String - Nexus host name + @param credentials String - User's name and pass in Nexus */ Nexus(Script script, String host, String credentials) { this.script = script @@ -28,7 +28,7 @@ class Nexus implements Serializable { @param repository String - Name of Nexus repository @param path String - Path in Nexus repository @param artifactName String - Name of artifact in Nexus (optional). Common calculate from artifactPath - @param type String - type of repository + @param type String - type of repository @return String - artifact url in Nexus */ public String upload(Map args = [:], String type = "raw") { @@ -48,9 +48,9 @@ class Nexus implements Serializable { /** * Method get artifacts' urls from nexus repository - @param repository String - Repository name in Nexus. - @param type String - type of repository - @return List - list of artifacts' urls + @param repository String - Repository name in Nexus. + @param type String - type of repository + @return List - list of artifacts' urls */ public List search(String repository, String type = "raw") { String newUrl = "" @@ -96,7 +96,31 @@ class Nexus implements Serializable { return urls } + /** + * Download artifact from Nexus repo + * + @param url String - URL, откуда будет скачан файл + @param outputFile String - Путь с именем файла, по которому будет сохранен(optional). + * По умолчанию с именем сохраняется в текущей директории с именем файла + @return Srting - Возвращает имя загруженного файла + */ + String download(String url, String outputFile = '') { + String artifactName = url.split('/').last() + String artifact = outputFile ?: "${this.script.pwd()}/${artifactName}" + + this.script.httpRequest( + url: url, + authentication: this.credentials, + httpMode: "GET", + quiet: true, + outputFile: artifact + ) + + return artifact + } + + /** * Method get artifact's info from nexus @param repository String - Repository name in Nexus. @param name String - Artifact path in Nexus.