1
votes

I'm having trouble downloading a build from my artifactory server to my windows jenkins slave node using the jenkins pipeline plugin. It all appears to be going fine, but it doesn't actually download the file. Am I doing something wrong?

I don't see any requests in my Artifactory system logs to download, just to upload.

(2017-04-25 18:39:48,096 [http-nio-8081-exec-2] [INFO ] (o.a.e.UploadServiceImpl:516) - Deploy to 'BUILDS:windows/5840/build.tar.gz' Content-Length: 278600525)

I've been using this as a reference: https://wiki.jenkins-ci.org/pages/viewpage.action?pageId=99910084


Here's the output from my jenkins pipeline:

For pattern: build.tar.gz 1 artifacts were found.
Deploying artifact: http://myartifactory:8081/artifactory/BUILDS/windows/5840/build.tar.gz
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] timeout
Timeout set to expire in 3 min 0 sec
[Pipeline] {
[Pipeline] node
Running on test-windows-0 in C:/jenkinsroot/workspace/test-windows
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] echo
{
        "files": [
                {
                    "pattern": "BUILDS/windows/5840/build.tar.gz",
                    "target": "download/",
                }
            ]
        }
[Pipeline] echo
Artifactory Download: BUILDS/windows/5840/build.tar.gz -> download/

The file exists on artifactory.


Here's my jenkins code:

@NonCPS
def downloadArtifactory(String localPath, String repository, String remotePath) {

    def downloadSpec = """{
        "files": [
                {
                    "pattern": "${repository}/${remotePath}",
                    "target": "${localPath}",
                }
            ]
        }"""

    echo "${downloadSpec}"

    echo "Artifactory Download: ${repository}/${remotePath} -> ${localPath}"

    def server = Artifactory.server("MYARTIFACTORYSERVER")
    def buildInfo = server.download spec: downloadSpec
    return buildInfo
}

Called with:

downloadArtifactory("download/", "BUILDS", "windows/5840/build.tar.gz")
2
From your echo statements it looks like your def downloadSpec is creating an empty variable called downloadSpec. Perhaps the triple quote at the beginning of the spec statement is confusing it and you are only getting the first two quote marks assigning it an empty string.Tuffwer
@Tuffwer: It seems to be printing the downloadSpec variable ok though, isn't it? I use the same format for uploading. I'm confused :)Jordan
You're right I read an extra echo statement in there. After looking through the page you mentioned I'm wondering if you need to invoke the download differently though. The example for executing the download on the page is server.download(downloadSpec).Tuffwer
Yeah, I've tried that too, unfortunately. The example here (github.com/JFrogDev/project-examples/blob/master/…) gives it in the format I'm currently tryingJordan
try removing the comma at the end of your target line, none of the examples have commas at the end of the last line in that part of the spec.Tuffwer

2 Answers

4
votes

Removing the NonCPS annotation should solve the problem.
As you can see in this Jenkins issue, Artifactory Jenkins plugin does not support NonCPS.

0
votes

Please remove the ,(comma) from the line "target": "${localPath}"

,

It works make it,

def downloadArtifactory(String localPath, String repository, String remotePath) {

def downloadSpec = """{
    "files": [
            {
                "pattern": "${repository}/${remotePath}",
                "target": "${localPath}"
            }
        ]
    }"""

echo "${downloadSpec}"

echo "Artifactory Download: ${repository}/${remotePath} -> ${localPath}"

def server = Artifactory.server("MYARTIFACTORYSERVER")
def buildInfo = server.download spec: downloadSpec
return buildInfo

}