DO-47/shared_libs_part2 (#2)

add Nexus class
This commit is contained in:
Aleksandr Vodyanov
2023-09-08 12:03:15 +00:00
parent ecc7728355
commit 87f0b4658f

View File

@@ -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
}
}