Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 529
Lieven Cardoen Avatar asked Jul 03 '15 13:07

Lieven Cardoen


1 Answers

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.

like image 138
Slav Avatar answered Oct 02 '22 06:10

Slav