1
votes

I have a Jenkins job which generate a zip file I want to updload to Artifactory. I have an issue setting the version of the artifact to be uploaded.

By convention, I use the timestamp has version. I want to upload file to my/group/timestamp/file.zip. The url of the file would be http://ArtifactoryAdress/foo/my/group/timestamp/file.zip

Here is my pipeline code

def serverArtifactory = Artifactory.server 'NameArtificatory'
def uploadSpec = """{
      "files": [
        {
          "pattern": "file.zip",
          "target": "my/group/${timestamp}/"
        }
     ]
    }"""
serverArtifactory.upload(uploadSpec)

I get the following error from Jenkins Job

java.lang.RuntimeException: java.io.IOException: Failed to deploy file. Status code: 400 Response message: Artifactory returned the following errors: Parent my/group/timestampValue must be a folder Status code: 400

I looked around buildInfo but was not able to find how to set a version.

By the way, I am also agree with a solution without the timestamp but only group name.

2
Is there something happening beyond the error message? It seems self-explanatory to me.Matt Schuchard
Make sure you didn't create a file "timestampValue" at the pattern "my/group". If this is the case, just delete the file and everything should work fine.Dima Nevelev
Thanks, I didn't realized a file already exist (coming from previous tests)Flows

2 Answers

2
votes

Finally, this error is clear and simple.

As mentioned, a file with path my/group/timestampValue already exists. You have to delete it on Artifactory.

0
votes

Don't forget it's still groovy use ${}. I used below code and it's work

def uploadSpec = """{
    "files": [
    {
    "pattern": "**/target/*.war",
    "target": "local-release/${APP_REPO}/${version.trim()}/${timestamp}.zip"
    }
    ]}"""
server.upload(uploadSpec)

@Edit. And I just thought about it. Print please your ${timestamp}. Maybe it's contains characters with spaces, or something like this which Artifactory not allowed in directory name. Try trim your timestamp.trim()