From 87f0b4658ffc4832f3de475063ba25ef684a365e Mon Sep 17 00:00:00 2001 From: Aleksandr Vodyanov Date: Fri, 8 Sep 2023 12:03:15 +0000 Subject: [PATCH] DO-47/shared_libs_part2 (#2) add Nexus class --- src/tech/avroid/api/Nexus.groovy | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/tech/avroid/api/Nexus.groovy diff --git a/src/tech/avroid/api/Nexus.groovy b/src/tech/avroid/api/Nexus.groovy new file mode 100644 index 0000000..90be7f1 --- /dev/null +++ b/src/tech/avroid/api/Nexus.groovy @@ -0,0 +1,41 @@ +package tech.avroid.api + +class Nexus implements Serializable { + + private script + private host + private credentials + + Nexus(Script script, String host, String credentials) { + this.script = script + this.host = host + this.credentials = credentials + } + + /** + * Upload artifact in Nexus. + * When call method need either artifactUrl or repository, and path + * either + * + @param artifactPath String - Local path to artifact + @param artifactUrl String - URL (optional) + @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 String type type of Repository + */ + public String upload(Map args = [:], String type = "raw") { + String artifactName = args.artifactName ?: args.artifact.split('/').last() + String artifactUrl = args.artifactUrl ?: "${host}/repository/${args.repository}/${args.path}/${artifactName}" + + script.httpRequest( + url: artifactUrl, + authentication: credentials, + httpMode: "PUT", + uploadFile: "${args.artifactPath}", + validResponseCodes: "201", + wrapAsMultipart: false + ) + return artifactUrl + } +}