Artifactory - Use Jenkins Pipeline script to upload

早过忘川 提交于 2019-12-11 07:42:22

问题


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

            }
        }
    } 
}

Artifactory 5.4.6


回答1:


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.

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().

Try this:

pipeline {
    agent any

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

                 server.upload(uploadSpec) 
               }
            }
        }
    } 
}



回答2:


I had an issue where I was using the correct syntax, and not seeing any errors, but still not seeing an artifact uploaded. Instead of a Jenkins log like:

[Pipeline] { (upload)
[Pipeline] script
[Pipeline] {
[Pipeline] bat
[libraries_PR-1-WWJNY63HBCEAKKTFO6WL2V5LW] Running batch script
[Pipeline] getArtifactoryServer
[Pipeline] newBuildInfo
[Pipeline] artifactoryUpload
[consumer_0] Deploying artifact: https://my.artifactory.net/path/
[Pipeline] }

I was seeing:

[Pipeline] { (upload)
[Pipeline] script
[Pipeline] {
[Pipeline] bat
[libraries_PR-1-WWJNY63HBCEAKKTFO6WL2V5LW] Running batch script
[Pipeline] getArtifactoryServer
[Pipeline] newBuildInfo
[Pipeline] artifactoryUpload
[Pipeline] }

This was because my path wasn't specified correctly, so no files matched it. Changing the path caused everything to work.



来源:https://stackoverflow.com/questions/46832989/artifactory-use-jenkins-pipeline-script-to-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!