41
src/tech/avroid/api/Nexus.groovy
Normal file
41
src/tech/avroid/api/Nexus.groovy
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user