如何使用ant将文件从Unix共享复制到Windows机器?

Lie*_*oen 6 unix ant ant-contrib jenkins

我在Unix机器上有一些文件,我可以使用\ host \目录从Windows资源管理器访问Windows资源管理器

但是,当使用ant copy任务时,ant继续说该目录不存在...

所以,蚂蚁部分是:

<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>
Run Code Online (Sandbox Code Playgroud)

这个输出是:

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.
Run Code Online (Sandbox Code Playgroud)

如果我尝试使用远程Windows网络路径,它确实有效......

知道如何解决这个问题吗?似乎很奇怪,我可以使用我的Windows资源管理器访问\ hyperion\dbs,但蚂蚁显然不能......

Unix是CentOs 6.5,但我想这没关系.

一些额外的信息.我创建了一个小的build.xml脚本,用于将文件从Unix机器复制到Windows机器.如果我从命令行执行build.xml ant脚本(顺便不以管理员身份启动),则输出为:

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
Run Code Online (Sandbox Code Playgroud)

从Jenkins执行此build.xml脚本时,我得到以下输出:

[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
Run Code Online (Sandbox Code Playgroud)

似乎无法弄清楚有什么区别.cmd.exe必须像其他用户一样执行吗?我只是在这里猜测,但是从我在Windows的命令行中,我正在以域用户身份执行ant.也许这和詹金斯有什么不同?

Ant脚本:

<?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>
Run Code Online (Sandbox Code Playgroud)

Sla*_*lav 2

似乎无法弄清楚有什么区别。cmd.exe 必须以其他用户身份执行吗?

100%。不仅用户不同,而且%PATH%您可能已缓存的任何凭据也不同。此外,您的ant可执行文件也不同。逃避cmd你有什么应对之策%PATH%。通过 Jenkins 运行,使用 Jenkins 的安装之一。但这不是这里的问题。

Jenkins 用户取决于您的设置方式。如果是Windows服务,通过Windows服务对话框管理用户,将其从“本地系统”更改为您更熟悉的用户,例如您自己的用户。

首先要检查几件事。

  • 您甚至可以通过 Jenkins 对主机执行 ping 操作吗?
    配置“执行批处理命令”步骤,然后只需键入ping srv-linuxdev。通过詹金斯执行。看看是否有效。

  • 如果完全省略标签,您还可以复制文件吗available

  • 如何设置访问linux共享的权限?是100%开放的吗?对于哪个用户?我没有看到您的案例中传递了任何凭据。凭据是否缓存在您的用户会话中?这一切都与 Jenkins 以不同用户身份运行有关。