using ssh and rsync in makefile - makefile

I came across the following code in a makefile.
ifdef MYBUILD
.PHONY: rsync all, clean
all: rsync
ssh $(MYBUILD) make -C cs/src
clean: rsync
ssh $(MYBUILD) make -C cs/src $#
rsync:
ssh $(MYBUILD) mkdir -p cs/src
rsync -Cavuz . $(MYBUILD):cs/src
I can't seem to understand what ssh and rsync would be doing in a make system? Can someone explain the above usage.

The Makefile allows you to run building on a build machine rather than your localhost. (Whether or not this is needed, you need to decide).
The all target will first have the rsync target performed and then will ssh to the remote system and run make there.
The rsync target will make sure your local source files are copied to the build machine.
If you want to test it, set up a separate build machine with SSH access using keyfiles, put that machine to some nice address or domain name (I will use 192.168.1.111) and then run
make MYBUILD="192.168.1.111"

Related

Jenkins - If a build fails deploy the artifacts of the last successful build

Is it possible with Jenkins to deploy the artifacts of the last successful build if the current one fails at any point? If so how?
I'm currently using rsync to deploy my files from the workspace as one of my build steps.
I'm aware that there is a plugin called BuildResultTrigger which I can guess I can use but I have no idea how to access archived artifacts and tell my current build which one was the last successful build.
I recommend that when deploying, you copy the already deployed (successfully built and tested) version to someplace on the deployment machine.
Then, when running the tests on Jenkins (assuming you use command-line to start the tests):
ssh deploymentmachine rm -rf /where/you/store/them
ssh deploymentmachine cp -R /where/you/deploy/them /where/you/store/them
rsync -rvz /where/jenkins/built/the/files deploymentmachine:/where/you/deploy/them
ssh deploymentmachine sh runtests.sh || \
(ssh deploymentmachine rm -rf /where/you/deploy/them; \
ssh deploymentmachine cp -R /where/you/store/them /where/you/deploy/them; \
ssh deploymentmachine rm -rf /where/you/store/them
exit 1)
ssh deploymentmachine rm -rf /where/you/store/them
This should give you a false exit status on failure and re-deploy the last successful version.
Adapt the solution as needed (for example, you probably start the tests in another way than "sh runtests.sh", the deployment may require re-starting servers instead of just copying around files, and the directory paths need adjusting).

run 'cordova prepare ios' from different folder

how can I run 'cordova prepare ios' from a different folder? Just perhaps from the parent folder of the app i try to build and prepare. Or from a shell script (but cd to folder doesn't work either within a shell script - console works perfectly!)
Build works with this:
/Users/someone/cordova/appname/platforms/ios/cordova/build
But there is no prepare inside the ios/cordova/ folder.
prepare is located #
/usr/local/lib/node_modules/cordova/bin/cordova prepare ios
How can I set a path? --path /Users/someone/cordova/appname/ doesn't work.
Or some other ideas?
Thanks!
****update****
This doesn't work (also pushd, popd):
ssh -l username -o 'HostKeyAlias example.com' example.com "(cd /Users/someone/cordova/appname && /usr/local/lib/node_modules/cordova/bin/cordova prepare ios)"
env: node: No such file or directory
But if I use just ls or pwd I'll get the correct path.
I tried also this:
ssh -l username -o 'HostKeyAlias example.com' example.com <<'ENDSSH'
cd /Users/someone/cordova/appname
cordova prepare
ENDSSH
****solution****
I already got it! (https://stackoverflow.com/a/1472444/2192501)
ssh -l username -o 'HostKeyAlias example.com' example.com "source /etc/profile;cd /Users/someone/cordova/appname;cordova prepare)"
the method to run commands from a different folder in a bash script is 'cd'
you can also look at pushd and popd http://en.wikipedia.org/wiki/Pushd_and_popd
another method to try would be
(cd path/to/cordova/project && cordova prepare ios)
this will spawn a subshell, change the working directory to the cordova project, execute the cordova prepare command, then close. This won't alter the working directory of the shell you execute from.
the prepare file which eventually gets executed is based on the platform arguments, and is downloaded off of your node_modules folder. It is called by the Cordova CLI with the correct arguments, including the path to the cordova project. The Cordova CLI knows where your cordova project is implicitly, because you executed the commands from the project root
I already got it! (https://stackoverflow.com/a/1472444/2192501)
ssh -l username -o 'HostKeyAlias example.com' example.com "source /etc/profile;cd /Users/someone/cordova/appname;cordova prepare)"

SSH remote command executing a script

I have two hosts, hosts A and B. A has a script (generate) that compiles my thesis:
#!/bin/sh
pdflatex Thesis.tex
When running this command on host A (console window) it works perfectly.
I am basically trying to connect from host B to A and run the generation command as an ssh remote command. All the keys are properly set. When I run the command, I get the following:
hostB> ssh user#hostA exec ~/Thesis/generate
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
! I can't find file `Thesis.tex'.
<*> Thesis.tex
I tried adjusting the script so that it considers the directory:
pdflatex ~/Thesis/Thesis.tex
But because the Thesis.tex inputs some others files (images), I get an error message.
I presume the problem is some sort of enviroment that doesn't exist in remote commands. How do I fix this?
ssh will run your command in your home directory. You probably wanted to run it in your ~/Thesis directory.
Just cd first and it should be fine:
ssh user#hostA 'cd ~/Thesis && ./generate'

Jenkins not able to execute ssh script

I have below ssh script which I am trying to execute by Jenkins, it runs fine when I invoke it from shell.
#ssh to remote machine
sshpass ssh 10.40.94.36 -l root -o StrictHostKeyChecking=no
#Remove old slave.jar
rm -f slave.jar
#download slave.jar to that machine
wget http://10.40.95.14:8080/jnlpJars/slave.jar
pwd
#make new dir to that machine
mkdir //var//Jenkins
# make slave online
java -jar slave.jar -jnlpUrl http://10.40.95.14:8080/computer/nodeV/slave-agent.jnlp
When I execute this script through shell it downloads the jar file to remote machine and also makes a new directory. But When I invoke it by shell plugin of jenkins, every command runs seprately. so the jar gets downloaded at master and also directory get created at master.
Also I am using sshpass for passwordless automated login, which fails sometime. Is there any other way of doing this.

Why does the lftp mirror command chmod files

I'm very new to lftp, so forgive my ignorance.
I just ran a dry run of my lftp script, which consists basically of a line like this:
mirror -Rv -x regexp --only-existing --only-newer --dry-run /local/root/dir /remote/dir
When it prints what it's going to do, it wants to chmod a bunch of files - files which I grabbed from svn, never modified, and which should be identical to the ones on the server.
My local machine is Ubuntu, and the remote is a Windows server. I have a few questions:
Why is it trying to do that? Does it try to match file permissions from the local with the remote?
What will happen when it tries to chmod the files? As I understand it, Windows doesn't support chmod - will it just fail gracefully and leave the files alone?
Many thanks!
Use the -p option and it shouldn't try to change permissions. I've never sent to a windows host, but you are correct in that it shouldn't do anything to the permission levels on the windows box.
I think that you should try
lftp -e "mirror -R $localPath $remotePath; chmod -R 777 $remotePath; bye" -u $username,$password $host

Resources