I'm using Jenkins/ant in order to deploy my applications to remote servers.
I was having issues with the ant <scp>
task for trying to scp a set of directories specified by a wildcard (e.g. 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.
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
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.
EDITS:
Trying out @whiskeyspider's config, see below:
<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:
[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.
You need to launch a shell, in order for the wildcard to expand. For example:
<exec executable="sh">
<arg value="-c"/>
<arg value="scp"/>
...
</exec>