Question

I am trying to build simple deployment system with bash script. I have tried checking TeamCity and similar products, but they are too difficult and needs lots of time to understand configure ect. So my idea is to create bash script which:

  1. connect to server using ssh
  2. get current revision
  3. svn update
  4. run unit tests
  5. if tests failed -> svn up -rXXX

What I have achieved: I am running sshpass -p 'pass' ssh user@IP "svn up; sh tests.sh"; which downloads commited changes to my server and runs all phpunit test.

The problem is that if my tests fail I need to revert chainges manually. I could get current revision using svn info | grep "Revision" | awk '{print $2}' and get bask to it, but I cannot find the way to check if tests failed in tests.sh. Anyone has any ideas how to achieve this? Or maybe you have better suggestions to achieve same results?

Was it helpful?

Solution

I have built it using @gontrollez hint. ./deploy script:

reset; 
sshpass -p 'pass' ssh dev@IP "./update";
RET=$?;
if [ $RET -eq 0 ];then
    sshpass -p 'pass' ssh test@IP "./update";
    RET=$?;
    if [ $RET -eq 0 ];then      
        sshpass -p 'pass' ssh prod@IP "./update";
        RET=$?;
        if [ $RET -eq 0 ];then      
            reset;
            echo "$(tput setaf 2)Success!"
        else
            echo "$(tput setaf 1)PROD test failed!"
        fi
    else
       echo "$(tput setaf 1)TEST test failed!"
    fi
else
   echo "$(tput setaf 1)DEV test failed!"
fi
echo "$(tput sgr0)"

./update script:

current=$(svn info | grep "Revision" | awk '{print $2}');
svn up;
sh tests.sh;
OUT=$?;
if [ $OUT -eq 0 ];then      
    echo "Update successful!"
else
    echo "Test failed! Reverting...";
    svn up -r$current;
    $(exit 10);
fi

And tests.sh runs phpunit tests

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top