pipeline - groovy - file paths on windows?

6,510 views
Skip to first unread message

Jonathan Hodgson

unread,
Oct 14, 2016, 6:17:25 PM10/14/16
to Jenkins Users
Hi,

I have a bit of code that looks like this

        def source_folder_name = "${pwd()}/${destination}"
        def source_folder = new File(source_folder_name)
        if (!source_folder.exists())
        {
            echo "Source folder ${source_folder_name} does not exist"
        }
        else
        {
            echo "Deleting folder ${source_folder_name}"
            source_folder.deleteDir()
        }

Now on Linux (on the master) it works fine.

On Windows (on a slave) it insists the folder does not exist, even though it does.

The folder is on the local machine in both cases.

I have tried replacing all forward slashes in the path with backslashes, and vice-versa but it doesn't seem to make any difference.

Am I missing something?

Rachel

unread,
Oct 15, 2016, 1:05:45 PM10/15/16
to Jenkins Users
Hi Jonathan,

You might check:
  • When it's said "Source folder <path> does not exist", check that <path> really exists and it's right.
  • Jenkins process on slave has permissions on that path.
I hope be useful.

Best regards,
Rachel

Jonathan Hodgson

unread,
Oct 17, 2016, 10:08:32 AM10/17/16
to Jenkins Users


On Saturday, October 15, 2016 at 6:05:45 PM UTC+1, Rachel wrote:
Hi Jonathan,

You might check:
  • When it's said "Source folder <path> does not exist", check that <path> really exists and it's right.
  • Jenkins process on slave has permissions on that path.
I hope be useful.

Best regards,
Rachel



Hi Rachel,

It certainly does exist.

Looking at the documentation, it seems that paths like "C:" should work, but they don't seem to.

Perhaps there is some subtlety about the path syntac that I'm missing?

  

Martina

unread,
Oct 17, 2016, 10:44:39 AM10/17/16
to Jenkins Users
What exactly is the value of ${source_folder_name} that is in the message?
C:/some-dir/some-other-name should definitely work.

Martina
  

Jonathan Hodgson

unread,
Oct 17, 2016, 10:56:31 AM10/17/16
to Jenkins Users
I've just done some experimentation, and 

    testfile = new File("/tmp/CheckOnServer.txt")
    if (testfile.exists())
    {
        echo "It's looking on the master"
    }
    else
    {
        echo "It's not looking on the master"
    }



gives

[Pipeline] [Windows] echo
[Windows] It's looking on the master


Now [Windows] is my slave (the master is a linux machine), but, as the message says, that file it is finding is on the master.

Paths seem to be failing because it's starting in the wrong place.

Jonathan Hodgson

unread,
Oct 17, 2016, 2:36:54 PM10/17/16
to Jenkins Users
I've tried every path variation I can think of

    def paths = [
        "c:",
        "c:\\",
        "c:\\Jenkins",
        "c:\\Jenkins\\workspace\\",
        "c:\\Jenkins\\workspace\\WPF-TryBuild",
               "c:/",
        "c:/Jenkins",
        "c:/Jenkins/workspace/",
        "c:/Jenkins/workspace/WPF-TryBuild",        
            "C:\\",
        "C:\\Jenkins",
        "C:\\Jenkins\\workspace\\",
        "C:\\Jenkins\\workspace\\WPF-TryBuild",
            "C:/",
        "C:/Jenkins",
        "C:/Jenkins/workspace/",
        "C:/Jenkins/workspace/WPF-TryBuild"
        ]
    for (path in paths)
    {
        try {
            def hg_folders = new FileNameFinder().getFileNames(path, '*')
            echo "SUCCESS!! Found $path"
        }
        catch(Exception err) {
            echo "There was a problem finding $path"
            echo err.getMessage()
        }
    }


The result is this

[Windows] There was a problem finding c:
[Windows] /c: does not exist.

[Windows] There was a problem finding c:\
[Windows] /c: does not exist.

[Windows] There was a problem finding c:\Jenkins
[Windows] /c:/Jenkins does not exist.

[Windows] There was a problem finding c:\Jenkins\workspace\
[Windows] /c:/Jenkins/workspace does not exist.

[Windows] There was a problem finding c:\Jenkins\workspace\WPF-TryBuild
[Windows] /c:/Jenkins/workspace/WPF-TryBuild does not exist.

[Windows] There was a problem finding c:/
[Windows] /c: does not exist.

[Windows] There was a problem finding c:/Jenkins
[Windows] /c:/Jenkins does not exist.

[Windows] There was a problem finding c:/Jenkins/workspace/
[Windows] /c:/Jenkins/workspace does not exist.

[Windows] There was a problem finding c:/Jenkins/workspace/WPF-TryBuild
[Windows] /c:/Jenkins/workspace/WPF-TryBuild does not exist.

[Windows] There was a problem finding C:\
[Windows] /C: does not exist.

[Windows] There was a problem finding C:\Jenkins
[Windows] /C:/Jenkins does not exist.

[Windows] There was a problem finding C:\Jenkins\workspace\
[Windows] /C:/Jenkins/workspace does not exist.

[Windows] There was a problem finding C:\Jenkins\workspace\WPF-TryBuild
[Windows] /C:/Jenkins/workspace/WPF-TryBuild does not exist.

[Windows] There was a problem finding C:/
[Windows] /C: does not exist.

[Windows] There was a problem finding C:/Jenkins
[Windows] /C:/Jenkins does not exist.

[Windows] There was a problem finding C:/Jenkins/workspace/
[Windows] /C:/Jenkins/workspace does not exist.

[Windows] There was a problem finding C:/Jenkins/workspace/WPF-TryBuild
[Windows] /C:/Jenkins/workspace/WPF-TryBuild does not exist.


Those paths most certainly do exist, 

Martina

unread,
Oct 17, 2016, 3:36:55 PM10/17/16
to Jenkins Users
So you solved the issue of it running on the wrong system, right?
Well, all the "does not exist" messages have a leading /.
Not sure where that comes from, but I'm pretty sure that that is what it is complaining about. Also, looking at FileNameFinder, all examples are it finding files, not directories, but examples are clearly using c:/path/path syntax.
I'm thinking you may want to try changing up your wildcard to something like '**/*.xml' or '**/*.txt', whatever you actually have on that file system.

hth
Martina

Jonathan Hodgson

unread,
Oct 17, 2016, 4:07:09 PM10/17/16
to Jenkins Users


On Monday, October 17, 2016 at 8:36:55 PM UTC+1, Martina wrote:
So you solved the issue of it running on the wrong system, right?

No, I haven't solved the issue.

I thought perhaps it was running on the wrong system because it didn't have an absolute path that it recognized as such, so I was trying to see if there was a path syntax which made it look locally, so far, no luck

Well, all the "does not exist" messages have a leading /.
Not sure where that comes from, but I'm pretty sure that that is what it is complaining about. Also, looking at FileNameFinder, all examples are it finding files, not directories, but examples are clearly using c:/path/path syntax.
I'm thinking you may want to try changing up your wildcard to something like '**/*.xml' or '**/*.txt', whatever you actually have on that file system.

FilenameFinder works as expected on the master, but not on the slave. It doesn't matter what my wildcard is, it always looks on the master. The same goes for File... which seems to be the complete opposite of what the documentation on File and FilePath says. If I understand that correctly, File is always supposed to look on the current machine (i.e. the one that node is running on) and so to access stuff on the master you have to use FilePath


Rachel

unread,
Oct 17, 2016, 4:19:45 PM10/17/16
to Jenkins Users
Hi Jonathan,

According to master and slave systems you have, I think you might use the option:
  • "Restrict where this project can be run"
in your job configuration (located in General Configuration), in order to force job execution on slave.


I hope be useful.

Best regards,
Rachel


Jonathan Hodgson

unread,
Oct 17, 2016, 4:44:03 PM10/17/16
to Jenkins Users
But I don't want to restrict where the job runs, just where the node runs.

I have code that needs to run on the master, and code that needs to run on the slaves.

The code is running in the correct places, I can for example do a mercurial checkout on the slaves, I can also run batch files on the slaves, and visual studio (or I could, that bit's disabled as I'm working on this, but it worked before).

Buildsteps do what they should, on the slave

but groovy file commands don't.

Jonathan Hodgson

unread,
Oct 17, 2016, 6:27:08 PM10/17/16
to Jenkins Users
Well I can confirm that it has nothing to do with it being windows, just tried FileNameFinder on my OSX slave and it also looks on the master

Jonathan Hodgson

unread,
Oct 17, 2016, 7:17:13 PM10/17/16
to Jenkins Users
Rachel and Martina,

Thanks for trying to help me on this, I've started a new thread now that I've realized the issue isn't to do with windows or paths, but rather to do with slaves and masters.

Rachel

unread,
Oct 18, 2016, 2:59:55 PM10/18/16
to Jenkins Users
Hi Jonathan,

Thanks for the information. I'll follow the new thread.

Best regards,
Rachel
Reply all
Reply to author
Forward
0 new messages