jfrog / project-examples

Small projects in universal build ecosystems to configure CI and Artifactory
1.01k stars 2.39k forks source link

Unable to upload artifacts #276

Closed prawen closed 3 years ago

prawen commented 3 years ago

Hello,

I'm not sure if I'm consuming the plugin properly. I have installed https://plugins.jenkins.io/artifactory/ plugin and the version is 3.10.6 I'm able to upload artifacts from the free style job.

I'm facing issues when integrated with pipeline.

        stage('Artifactory download and upload'){
            steps {
                script{
                    def server = Artifactory.server SERVER_ID
                    def uploadSpec = readFile 'props-upload.json'
                    def buildInfo = server.upload spec: uploadSpec
                    server.publishBuildInfo buildInfo
                }
            }
        }

  }

I have referred to example at https://github.com/jfrog/project-examples/blob/master/jenkins-examples/pipeline-examples/scripted-examples/declarative-example/Jenkinsfile

ERROR:

groovy.lang.MissingPropertyException: No such property: SERVER_ID for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)

I have tried below setting

def server = Artifactory.server ArtifactoryonAWS

ERROR:

groovy.lang.MissingPropertyException: No such property: ArtifactoryonAWS for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)

Below is my setting on Jenkins

Screenshot from 2021-04-28 18-13-21

Please let me know if you need additional details.

yahavi commented 3 years ago

@prawen, The issue you encounter looks like a Groovy issue - The Groovy expects a string, but it gets an unknown property. You can add quotes around ArtifactoryonAWS:

def server = Artifactory.server "ArtifactoryonAWS"

Another option is to define a job parameter ArtifactoryonAWS. Read more about it in the README.

One more thing - It looks like you're using declarative pipelines with the scripted pipelines syntax of the Jenkins Artifactory plugin. I'd recommend using declarative pipelines syntax. You can find many examples here.

Please let me know if that helped. If you have more questions please open an issue in the Jenkins Artifactory plugin GitHub repository: https://github.com/jfrog/jenkins-artifactory-plugin/issues/new/choose

prawen commented 3 years ago

Thank you. This has worked.

    stage('Upload Artifacts'){
     when {
        branch 'master'
      }          
      steps {
        rtUpload (
          serverId: 'ArtifactoryonAWS',
          specPath: 'props-upload.json'
                )
            }
        }

    stage ('Publish build info') {
     when {
        branch 'master'
      }      
      steps {
        rtPublishBuildInfo (
          serverId: 'ArtifactoryonAWS'
                )
            }
        }