Aakankshi Ar
Aakankshi Ar

Reputation: 11

How to replace Artifactory file "pattern" path dynamically in rtUpload in Jenkins Declarative Pipeline

I'am trying to dynamically replace my zip file pattern in rtDownload in my declarative jenkinsfile but the value is not taken up by the function.

A zip file with a newer version is created and uploaded on JFrog with every build and I want to download a particular version in my local system.

I have defined "VERSION" in def VERSION and used it as -

  rtDownload (
                    serverId: 'Jfrog',
                    
                    spec: '''{
                        "files": [
                            {
                            "pattern": "<path>-<filname>${VERSION}.zip",
                            "target": "<path>-<filename>${VERSION}.zip",
                            "flat": "true"
                            }
                        ]
                    }'''
                )  

But it does not replace my VERSION with the version I am providing through String parameter configured in the jenkins job.

Any suggestions would be greatly appreciated. Thanks.

Upvotes: 1

Views: 1484

Answers (1)

Noam Helmer
Noam Helmer

Reputation: 6859

In groovy single quote strings ('') and single quote multi line strings (''' ''') do not support string interpolation, only double quote strings support this.
You can read more info on string interpolation in groovy in the Official Documentation.

So to fix it just use double quoted multi line string, that will enable the evaluation of your parameters:

rtDownload (
    serverId: 'Jfrog',               
    spec: """{
          "files": [
              {
                 "pattern": "<path>-<filname>${VERSION}.zip",
                 "target": "<path>-<filename>${VERSION}.zip",
                 "flat": "true"
               }
           ]
     }"""
)  

Upvotes: 3

Related Questions