deployment - Jenkins build passes when ssh deploy fails -
i'm using here tag in jenkins build step send deploy commands on ssh, , unfortunately build passing when commands inside here tag don't finish successfully: ssh user@host <<eof cd /path/to/app git pull bower install npm install grunt build cp -r /path/to/app/dist/* /path/to/dist/ forever restartall exit eof
is there better way approach problem?
you not catching error codes inside "here document".
last command exit
, without exit code, default 0
success.
since last command of ssh
success, whole command treated success, , build success.
easiest way fix that: chain commands &&
so:
cd /path/to/app && git pull && bower install && npm install && grunt build && cp -r /path/to/app/dist/* /path/to/dist/ && forever restartall && exit
best way fix that: write proper shell script, with error handling, , execute that. if lazy error handle every line, can start script set -e
fail shell script on individual error
edit:
#!/bin/bash apppath="/path/to/app" distpath"/path/to/dist" echo "my great deployment script" echo "deploying ${apppath} ${distpath} if [[ ! -w "${apppath}" ]]; echo "${apppath} not writable, quitting" exit 1 else cd ${apppath} && git pull || { echo "failed on 'git pull'"; exit 2; } bower install || { echo "failed on 'bower install'"; exit 3; } npm install || { echo "failed on 'npm install'"; exit 4; } grunt build || { echo "failed on 'grunt build'"; exit 5; } if [[ -w "${distpath}" ]]; cp -r ${apppath}/dist/* ${distpath}/ || { echo "failed on 'copy'"; exit 1 } forever restartall || { echo "failed on 'forever restartall'"; exit 6 } echo "deployment successful" exit 0 fi fi
you execute with: ssh user@host 'bash -s' < myfile.sh
(if file local)
or if place file remotely, just: ssh user@host '/path/to/remote/myfile.sh'
Comments
Post a Comment