Hi,

I am trying to use the rest service copyArtifact, but I can't get it to
work. Feels like I have tried everything. I am trying to do this with
groovy and this is how my code looks at the moment. The info in
artifactTransferRequest is from the response of searchArtifacts

def copyArtifact() {
  def baseUrl = "..."
  def request = new RESTClient(baseUrl + "/restServices/archivaServices/")
  request.headers['Authorization'] = "Basic " +
("username:pass".bytes.encodeBase64().toString())
  request.handler.failure = { response ->
    println "Unexpected failure: ${response.status}"
  }
  def copyArtifactResponse = request.post(
    path: "repositoriesService/copyArtifact",
    contentType: JSON,
    requestContentType: XML,
    body: {
      artifactTransferRequest {
        targetRepositoryId  "tagged-releases"
        packaging           "dll"
        fileExtension       "dll"
        type                "dll"
        artifactId          "bla4"
        groupId             "se..."
        version             "2020.1"
        repositoryId        "release"
        context             "release"
        url                 "..."
      }
    }
  )

  println "Status: " + copyArtifactResponse.status
  if (copyArtifactResponse.data) {
    println("Content Type: " + copyArtifactResponse.contentType)
    println("Headers: " + copyArtifactResponse.getAllHeaders())
    println("Body:\n" +
JsonOutput.prettyPrint(JsonOutput.toJson(copyArtifactResponse.data)))
  }
}


Here is the response I get:
Unexpected failure: 500
Caught: java.lang.NullPointerException: Cannot get property 'status' on
null object
java.lang.NullPointerException: Cannot get property 'status' on null object

Regards
Anders

Reply via email to