Jinkens 部署rails 服务

2019-10-17  本文已影响0人  葫芦葫芦快显灵

最近把rails项目改为使用脚本部署后,每次发版都需要登录服务器,而且java项目使用的jenkins部署,故改为jenkins部署,这里记录一下踩的坑。

jenkins 会自动拉取相应分支的代码到节点上,注意:拉下来的项目并不会由分支名,而是上一次提代码的tag

#!/bin/bash -l                                  #-l 为login,必加,否则会在安装jenkins的服务器上执行脚本
export BUILD_ID=dontKillMe   # 必加,否则 jenkins 执行完脚本会杀死衍生的进程
./deploy.sh release-1.1                   # 部署脚本,  不要加sh

deploy.sh

#! /bin/bash
if [ -z $1 ]
then
    branch='master'
else
    branch=$1
fi
echo "$branch"
git checkout $branch
git pull
pids=$(cat tmp/pids/server.pid | awk $'{print $1}')
if [ ! -z $pids ]
then
    echo "$pids"
    kill -9 $pids
fi
bundle
rails db:migrate

env=$(cat /etc/profile | grep RAILS_ENV |awk $'{print $2}')
if [ $env = "RAILS_ENV=production" ]
then
    echo "Production"
    rails s -p 3000 -d
else
    echo "Staging"
    rails s -p 4000 -d
fi
上一篇 下一篇

猜你喜欢

热点阅读