Question: This snipped

```
   stage('get iter number') {
      steps {
        rtDownload (  // 
           serverId: 'MAIN-ARTIFACTORY',
           spec: '''{ "files": [{"pattern": "p1/p2/p3/${BUILD_ID}/n_iter.txt", "target": "./n_iter.txt"}] }''',
        )
      }
   }

```

where BUILD\_ID = 'a/b'
downloads file to a location $WORKSPACE/p2/p3/a/b/n\_iter.txt rather then expected $WORKSPACE/n\_iter.txt

Also, very strange - why p1 is not in downloaded path?

Answer: 
By default, artifacts are downloaded to the target path in the file system while maintaining their hierarchy in the source repository (not including the repository name - hence `p1` is missing in your example).

To download an artifact while ignoring the hierarchy, set `"flat": "true"` in your file spec.

For a more advanced control of the resulting hierarchy, you may want to use [Placeholders](https://www.jfrog.com/confluence/display/JFROG/Using+File+Specs#UsingFileSpecs-UsingPlaceholders).

See more information in the [File Specs documentation](https://www.jfrog.com/confluence/display/JFROG/Using+File+Specs).
Please try with the below snippet, which means all the files in the *com/my-files/* Artifactory repository-path will be downloaded into the *my-folder* directory on the Jenkins agent file system. For more details on this please do refer to our Declarative Pipeline Syntax wiki page [here](https://www.jfrog.com/confluence/display/JFROG/Declarative+Pipeline+Syntax#DeclarativePipelineSyntax-UploadingandDownloadingFiles).

```
rtDownload (
serverId: 'Artifactory-1',
spec: '''{
      "files": [
        {
          "pattern": "com/my-files/",
          "target": "my-folder/"
        }
      ]

```

In addition to the above, you can refer to the **rtDownload** example referred to in our GitHub page [here](https://github.com/jfrog/project-examples/blob/a95fe875fe594a2ac672ec2568285e33fbb8d351/jenkins-examples/pipeline-examples/declarative-examples/props-single-file-example/Jenkinsfile).