How to copy files from a Unix share to a Windows machine using ant?
Asked Answered
U

1

6

I have some files on a Unix machine which I can access from my Windows PC with Windows Explorer using \host\directory

However, when using an ant copy task, ant keeps on saying the directory doesn't exist...

So, the ant part is:

<if>
    <available file="${unix-dbs-dir}" type="dir" />
    <then>
        <echo message="${unix-dbs-dir} exists"/>
    </then>
    <else>
        <echo message="${unix-dbs-dir} doesn't exist"/>
    </else>
</if>

<copy todir="${dbsDir}" verbose="true">
    <fileset dir="${unix-dbs-dir}">
        <include name="*.bd"/>
    </fileset>
</copy>

The output of this is:

15:28:42      [echo] \\hyperion\dbs doesn't exist
15:28:42 
15:28:42 BUILD FAILED
15:28:42 ... \\hyperion\dbs does not exist.

If I try the same with a remote Windows network path, it does work...

Any idea how to fix this? Seems strange that I can just access \hyperion\dbs with my Windows Explorer, but ant apparently can't...

The Unix is a CentOs 6.5, but I guess that doesn't matter.

Some extra information. I've created a small build.xml script to copy a file from our Unix machine to a Windows machine. If I execute the build.xml ant script from the command line (not started as administrator by the way), then the output is:

C:\Users\lievenc\TestCopyHyperion>%ANT_HOME%/bin/ant.bat -lib lib
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.
0_45\lib\tools.jar
Buildfile: C:\Users\lievenc\TestCopyHyperion\build.xml
     [echo] Load them from directory \\srv-linuxdev\pde\appl\samplenet\dbs
     [echo] \\srv-linuxdev\pde\appl\samplenet\dbs exists
     [copy] Copying 1 file to C:\Users\lievenc\TestCopyHyperion
     [copy] Copying \\srv-linuxdev\pde\appl\samplenet\dbs\apif.d to C:\Users\lievenc\TestCopyHyperion\apif.d

When executing this build.xml script from Jenkins, I get following output:

[workspace] $ cmd.exe /C '"C:\Jenkins\tools\hudson.tasks.Ant_AntInstallation\1.9.4\bin\ant.bat -lib lib && exit %%ERRORLEVEL%%"'
Buildfile: C:\Jenkins\jobs\test-copying-from-hyperion\workspace\build.xml
     [echo] Load them from directory \\srv-linuxdev\pde\appl\samplenet\dbs
     [echo] \\srv-linuxdev\pde\appl\samplenet\dbs doesn't exist

Can't seem to figure out what the difference is. cmd.exe must be executed as some other user? I'm just guessing here, but from my command line in Windows, I'm executing ant as a Domain User. Maybe this is different from Jenkins?

Ant script:

<?xml version="1.0"?>

<project basedir="." xmlns:ac="antlib:net.sf.antcontrib">

    <!-- antcontrib -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

    <echo message="Load them from directory \\srv-linuxdev\pde\appl\samplenet\dbs" />

    <if>
        <available file="\\srv-linuxdev\pde\appl\samplenet\dbs" type="dir" />
        <then>
            <echo message="\\srv-linuxdev\pde\appl\samplenet\dbs exists"/>
        </then>
        <else>
            <echo message="\\srv-linuxdev\pde\appl\samplenet\dbs doesn't exist"/>
        </else>
    </if>

    <copy todir="${basedir}" verbose="true">
        <fileset dir="\\srv-linuxdev\pde\appl\samplenet\dbs">
            <include name="apif.d"/>
        </fileset>
    </copy>

</project>
Unconcerned answered 3/7, 2015 at 13:32 Comment(2)
have you tried in //hyperion/dbs format ?Sialagogue
Yes, have tried that. Also tried \\\\hyperion\\dbs...Unconcerned
S
2

Can't seem to figure out what the difference is. cmd.exe must be executed as some other user?

100%. Not only the user different, but so is the %PATH%, and any credentials you may have cached. Additionally, your ant executable is different too. Running from cmd you have whatever copes from %PATH%. Running through Jenkins, uses one of Jenkins' installations. However this wasn't the question here.

The Jenkins user depends on how you have it setup. If a Windows service, manage the user through Windows Services dialog, change it from "Local System" to something you are more familiar with, such as your own user.

Several things to check for first.

  • Can you even ping the host, through Jenkins.
    Configure an "Execute Batch Command" step, and just type ping srv-linuxdev. Execute through Jenkins. See if that works.

  • Can you still copy the file if you omit the available tag altogether?

  • How are the permissions setup to access the linux share? Is it 100% open? For which user? I don't see any credentials being passed in your case. Are the credentials cached on your user session? This all ties to Jenkins running as different user.

Stopped answered 6/7, 2015 at 16:50 Comment(5)
Windows service is set up with the same user as I used to test from the DOS Command Line (Domain User).Unconcerned
Ping works. Copying the file doesn't work, even if I omit the available.Unconcerned
Permissions are set up using Group Policy (IT Admin explained it to me). It should be 100% open for all Domain Users.Unconcerned
What's even more strange is that doing the same using a Windows share does work, so I'm in the dark here ;-)Unconcerned
Started Jenkins Windows Service as another user and now things do work, so IT is now looking for the reason. So it is a security issue.Unconcerned

© 2022 - 2024 — McMap. All rights reserved.