Jenkins pipeline + Artifactory 下载不下载

Jenkins pipeline + Artifactory download not downloading

我在使用 jenkins 管道插件将构建从我的人工制品服务器下载到我的 windows jenkins 从节点时遇到问题。 看起来一切正常,但实际上并没有下载文件。我做错了什么吗?

我在 Artifactory 系统日志中没有看到任何下载请求,只是上传请求。

(2017-04-25 18:39:48,096 [http-nio-8081-exec-2] [INFO] (o.a.e.UploadServiceImpl:516) - 部署到 'BUILDS:windows/5840/build.tar.gz' 内容-长度:278600525)

我一直以此为参考:https://wiki.jenkins-ci.org/pages/viewpage.action?pageId=99910084


这是我的詹金斯管道的输出:

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/

该文件存在于 artifactory 上。


这是我的詹金斯代码:

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

调用方式:

downloadArtifactory("download/", "BUILDS", "windows/5840/build.tar.gz")

删除 NonCPS 注释应该可以解决问题。
正如您在 this Jenkins issue 中看到的,Artifactory Jenkins 插件不支持 NonCPS。

请删除“target”行中的 ,(逗号):“${localPath}”

,

有效 成功了,

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

}