'jfrog artifactory - uploading with nested folders

I am trying to upload files to artifactory with more than 1 level folder in the path. According to jfrog docs it should be possible but it does not work as expected. Any ideas? https://www.jfrog.com/confluence/display/JFROG/Using+File+Specs

I have deploy function in groovy in jenkins using spec:

#!/usr/bin/env groovy

import Spec

def call(String repo, String dir, String version) {
    def spec = new UploadSpec()
    spec.setTargetRepo(repo)
    spec.setTargetDir(dir)
    spec.setTargetVersion(version)
    def uploadSpec = spec.getBuildUploadSpec(spec.targetRepo, spec.targetDir, spec.targetVersion)
    def server = Artifactory.server('serwer-001')
    server.upload(uploadSpec)
}

static GString getBuildUploadSpec(targetRepo, targetDir, targetVersion) {
    GString uploadSpec =
            """
            {
              "files": [
                {
                  "pattern": "${targetDir}",
                  "target": "${targetRepo}/${targetVersion}/"
                }
              ]
            }
            """
    return uploadSpec
}

and the result in jenkins log is:

[consumer_0] Deploying artifact: https://artifactory.xxxx.com/artifactory/repositoryName/folderA/FolderB/name.src.tar.gz

But on artifactory its being uploaded to path:

repositoryName
   folderA/FolderB
      name.src.tar.gz

instead of expected:

repositoryName
   folderA
      FolderB
         name.src.tar.gz


Solution 1:[1]

I used the same JenkinsFile at my end and could observe that the file is deployed in this manner "repo-name/folderA/fodlerB/file" as below enter image description here

However, folderA and folderB aren't concatenated, can you confirm this? There is clearly a separation between the folderA and folderB with '/'.

Solution 2:[2]

Actually folderB is a subfolder of folderA. since there are no other files under folderA, it is displaying like 'folderA/folderB'. for testing you place one more file under folderA , then you will be able to see the hierarchy.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muhammed Kashif
Solution 2 puneetky