Script deploy gotcha with Travis CI
Recently I was attempting to leverage the script deploy provider offered by Travis CI. This provider is similar to the after_success lifetime hook but adds additional customization in the form of offering the added capability to control deploys based on target branch.
deploy:provider: scriptscript: ./deploy.shon:branch: dev
Straight forward, obvious to understand, right? Well almost. When first deploying my application I was met with this nefarious error
- Script failed with status 127- failed to deploy
Some frantic googling led me to the conclusion that my script was not executable by Travis, which would make sense as my initial start log never fired
echo "###### Starting Deployment ######"
I then attempted to apply the following to my script in my git repository
git update-index --add --chmod=+x deploy.sh
Which, unfortunately, did not yield any meaningful result when merging from feature branch to deployment branch.
I did find that if I move this command into my Travis build script as a before_deploy method, it allows my deploy to run as intended.
before_deploy:- chmod +x ./deploy.sh.sh
Although this does work, I found it a little unsavory to need to run a command outside of my deploy logic block in order to run my custom script.
After further frantic googling, I stumbled across a rather elegant solution which suggested to apply the chmod in conjunction with the && operator.
chmod +x ./deploy.sh && ./deploy.sh
The beauty of this solution is that it removes the need to run chmod if our previous steps fail. And for completeness, here is my final deploy script, locked down to only deploy out of my dev branch, to protect against accidental deploys out of my feature branches
deploy:provider: scriptscript: chmod +x ./deploy.sh && ./deploy.shon:branch: dev