Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-67741

Jenkins Artifactory plugin "server.upload spec: uploadSpec" unable to upload multiple files in the loop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • artifactory-plugin
    • None
    • Jfrog jenkins-artifactory-plugin 3.15.3 (In a private environment)

      I have configured a Jenkins pipeline to upload files changed in the last commit to the jFrog artifactory. The pipeline has scripts and groovy methods to sort out the files which should be uploaded to the artifactory (e.g. based on specific file extensions). 

       

      All the steps implemented in Jenkinsfile. My pipeline looks like this

       

      import groovy.json.JsonSlurper@NonCPS
      
      def parseFileInfo(uploadFiles) {
          List listMaps = []
          if (uploadFiles == "No changes") {
              println("No file changes found in the lastest commit")
          } else {
              def getList = new JsonSlurper().parseText(uploadFiles)
              getList.each {listMaps.add(it)}
          }
          return listMaps
      }
      
      @NonCPS
      def artifactoryUpload(uploadFiles) {
          def deployFiles = parseFileInfo(uploadFiles)
          for (dFile in deployFiles) {
              println("Src: ${dFile['path']}, File: ${dFile['name']}, Channel: ${dFile['channel']}")
              def server = Artifactory.newServer url: "https://${afUrl}", credentialsId: "${afCredId}"
              def uploadSpec = """{
                  "files": [{
                      "pattern": \"${dFile['path']}\",
                      "target": \"${repoUrl}/builds/${dFile['channel']}/\"
                  }]
              }"""
              echo uploadSpec
              server.upload spec: uploadSpec
          }
      }
      
      pipeline {
          agent { label "python" }
          stages {
              stage ('Latest changes') {
                  steps {
                      script {
                          uploadFiles = checkFiles('latest_changes')
                      }
                  }
              }
              stage ('Deploy') {
                  when {
                      expression { UPLOAD_CHANGES == "true" }
                  }
                  steps {
                      script {
                          artifactoryUpload(uploadFiles)
                      }
                  }
              }
          }
      }
      
      

       

      Console output: 

       

      // I have this list of files in groovy list maps format to upload
      [   {
           "name": "channel.cfg",
           "channel": "a",
           "path": "channels/a/channel.cfg"
           },
           {
           "name": "channel.spc",
           "channel": "a",
           "path": "channels/a/channel.spc"
           },
           {
           "name": "channel.json",
           "channel": "a",
           "path": "channels/a/channel.json"
           }
       ]
      [Pipeline] { (Deploy)
      [Pipeline] script
      [Pipeline] {
      [Pipeline] echo
      Src: channels/a/channel.cfg, File: channel.cfg, Channel: a
      [Pipeline] newArtifactoryServer
      [Pipeline] echo
      {
                      "files": [{
                          "pattern": "channels/a/channel.cfg",
                          "target": "my-build/builds/a/"
                      }]
                  }
      [Pipeline] newBuildInfo
      [Pipeline] artifactoryUpload
      [consumer_0] Deploying artifact: https://xyz.com/artifactory/my-build/builds/a/channel.cfg
      [Pipeline] }
      [Pipeline] // script
      .
      .
      .
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      
      

       

      The upload stage iterate over list of files which will be uploaded via the artifactory plugin. The solution works fine if there is only one file change but if we have multiple files to upload it only uploads the first file in the loop and ignores rest of them according to the output you see in the console. 

      I am not getting why it's happening like this.

      Can anyone help me to resolve this problem? Any idea/suggestion? 

            hislam Habibul Islam
            hislam Habibul Islam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: