Forum Discussion

vpachpute1's avatar
vpachpute1
Frequent Contributor
8 years ago

Groovy : How to give absolute file path of file.

Hi   I want to give absolute file path in Groovy. I have following code.   // Option 1 : this works on my local. but not on Jenkins/maven which is on server. As there is relative path of my local...
  • nmrao's avatar
    8 years ago
    Since the path changes machine to machine, you need to use a variable / project level property, say BASE_DIRECTORY, set this value according to machine, here "/home/vishalpachupute" and rest of the path maintain the directory structure for the resources being used.

    In the script:

    def prefix = context.expand('${#Project#BASE_DIRECTORY}')
    def request = new File("${prefix}/API/Responses/Response_SelfFullTrans.xml").text