Artifactory-使用Jenkins Pipeline脚本上传 [英] Artifactory - Use Jenkins Pipeline script to upload

查看:642
本文介绍了Artifactory-使用Jenkins Pipeline脚本上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jenkins Pipeline脚本将一些二进制文件上传到Artifactory. 我使用了Artifactory的同一示例文档,但不起作用. 我遇到以下错误:

I'm trying to upload some binaries to Artifactory by using Jenkins Pipeline script. I used the same exemple from Artifactory documentation, but it doesn't work. I had the following error:

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.lang.String.upload() is applicable for argument types: (java.lang.String) values: [{
              "files": [
                       ....

还有另一个类似的问题,但没有任何回应...

There is another similar question but there is no response...

pipeline {
    agent any
    environment {
        def server = Artifactory.server 'art-1'
        def uploadSpec = """{
              "files": [
                {
                   "pattern": "path/",
                    "target": "path/"
                }
             ]
            }"""

    }
    stages {
        stage('upload') {
           steps {
              script { server.upload(uploadSpec) }

            }
        }
    } 
}

人工工厂5.4.6

推荐答案

您不是很正确地使用了声明式管道.环境部分不能那样工作.您只能在其中定义字符串,我以为def会引发错误,但显然不会.

You aren't using the declarative pipeline quite right. The environment section doesn't work like that. You can only define strings in there, and I would have thought that def would throw an error, but apparently not.

您可能最终以server等于对Artifactory.server对象的引用的String表示形式.基本上是Artifactory.server.toString().

You are likely ending up with server being equal to a String representation of the reference to an Artifactory.server object. Basically Artifactory.server.toString().

尝试一下:

pipeline {
    agent any

    stages {
        stage('upload') {
           steps {
              script { 
                 def server = Artifactory.server 'art-1'
                 def uploadSpec = """{
                    "files": [{
                       "pattern": "path/",
                       "target": "path/"
                    }]
                 }"""

                 server.upload(uploadSpec) 
               }
            }
        }
    } 
}

这篇关于Artifactory-使用Jenkins Pipeline脚本上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆