简体   繁体   English

Ant 在中找不到通配符目录<exec>任务</exec>

[英]Ant cannot find wildcard directory in <exec> task

I'm using Jenkins/ant in order to deploy my applications to remote servers.我正在使用 Jenkins/ant 将我的应用程序部署到远程服务器。

I was having issues with the ant <scp> task for trying to scp a set of directories specified by a wildcard (eg scp -r my/path/and/directory_* user@remote:/remote/path/to/directory), so I've been trying to just run it using the <exec> task instead.我遇到了 ant <scp>任务的问题,因为它试图对通配符指定的一组目录进行 scp(例如 scp -r my/path/and/directory_* user@remote:/remote/path/to/directory),所以我一直在尝试使用<exec>任务来运行它。

See code below:请参阅下面的代码:

<property name="built_directories" value="${workspace}/build_\*" />

<exec dir="${workspace}" executable="scp" failonerror="true">
    <arg line="-r -i ${user.home}/.ssh/id_rsa ${built_directories} deployer@@@{SERVER}:${remote_build_dir}"></arg>
</exec>

Jenkins/ant gives me the error:詹金斯/蚂蚁给我错误:

[exec] /var/lib/jenkins/jobs/app-head-stage-deployment/workspace/build_*: No such file or directory [exec] /var/lib/jenkins/jobs/app-head-stage-deployment/workspace/build_*: 没有那个文件或目录

I've also tried the following, but receive the same error:我也试过以下,但收到同样的错误:

<exec dir="${workspace}" executable="scp" failonerror="true">
     <arg value="-r"></arg>
     <arg value="-i"></arg>
     <arg value="${user.home}/.ssh/id_rsa"></arg>
     <arg value="${built_directories}"></arg>
     <arg value="deployer@@@{SERVER}:${remote_build_dir}"></arg>
</exec>

I've been trying to figure out if somehow I need to escape the asterisk in order for it to be parsed correctly by the shell, but haven't found much information.我一直在试图弄清楚是否需要以某种方式转义星号,以便 shell 正确解析它,但没有找到太多信息。

EDITS:编辑:

Trying out @whiskeyspider's config, see below:尝试@whiskeyspider 的配置,见下文:

<exec dir="${workspace}" executable="sh" failonerror="true">
    <arg value="-c" />
    <arg value="scp" />
    <arg value="-r" />
    <arg value="-i" />
    <arg value="${user.home}/.ssh/id_rsa" />
    <arg value="${built_directories} deployer@@@{SERVER}:${remote_build_dir}" />
</exec>

I've tried splitting the last arg into separate <arg> elements as well, but now I get the following error:我也尝试将最后一个 arg 拆分为单独的<arg>元素,但现在出现以下错误:

[exec] usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [exec] [-l limit] [-o ssh_option] [-P port] [-S program] [exec] [[user@]host1:]file1... [[user@]host2:]file2 [exec] usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [exec] [-l limit] [-o ssh_option] [-P port] [-S program] [exec ] [[user@]host1:]file1... [[user@]host2:]file2

And I'm guessing that means that it doesn't recognize the arguments properly.我猜这意味着它无法正确识别 arguments。

You need to launch a shell, in order for the wildcard to expand. 您需要启动一个shell,以便扩展通配符。 For example: 例如:

<exec executable="sh">
    <arg value="-c"/> 
    <arg value="scp"/>
    ...
</exec>

I ended up having to quote the string (though I probably could have figured out the specific character(s) that needed escaping:我最终不得不引用字符串(尽管我可能已经找出需要 escaping 的特定字符:

<exec executable="sh" osfamily="unix">
    <arg value="-c"/> 
    <arg line="'chmod uga+x ${project.build.directory}/dist/bin/*.sh'"/>
</exec>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM