你的位置:首页 > ASP.net教程

[ASP.net教程]jenkins 集成部署站点


 Jenkins 集成部署站点

最近为了在两台Linux中,去作jenkins的集成发布,所以在部署jenkins的这台电脑(A) 要把打包好的war 部署到远程服务器(B)

  • 在两台电脑间进行传输的时候,要配置一个免登入的配置
    1.1. 在A电脑上 ssh-keygen生成秘钥,同时把生成的id_ras.pub文件上传到B服务器(/home/${user}/.ssh/authorized_keys文件里)       1.2. 修改B服务器的 .ssh 文件属性为 700,authorized_keys为 600
  • 在A上写好 jenkins 部署的文件
  1. build_post.sh
 1 #! /bin/sh/ 2 #复制文件 3 echo "cp web.war  --------------->  ROOT.war" 4 #目标文件 5 rootfile=/opt/app/deploy/build/web/ROOT.war 6 #执行复制 7 cp -r -f /home/developer/.jenkins/workspace/web-build/build/web/libs/web.war $rootfile 8  9 10 echo "send file to remote server"11 #将本地文件上传的服务器12 sh /opt/app/deploy/web/upload.sh -f /opt/app/deploy/web/hostfile -s $rootfile -p web13 14 if [ $? -ne 0 ] ;then15 16 echo "execute upload shell failed"17 18 exit $?19 20 fi21 22 echo "send success"23 exit $?

 

  1. upload.sh的文件
 1 #! /bin/sh 2  3 echo "start sync war to remote server" 4  5  6 while getopts f:s:p: OPT;do 7     case $OPT in 8         f) 9          files="$OPTARG $files"10           ;;11          s)12         sourcefiles="$OPTARG"13         ;;14          p)15         project="$OPTARG"16 echo "project is $project"17         ;;18         *)19          echo "usage :`basename $0` [-f hostfile] [-s source file] <from><to>"20          exit 221          esac22          done23 24 25 shift `expr $OPTIND - 1`26 27 28 if [ "" == "$project" ] ;then29 echo "usage: `basename $0` [-p project]"30 exit 231 fi32 33 if [ "" == "$sourcefiles" ] ;then34 echo "usage:`basename $0` [-s sourcefile]"35 exit 236 fi37 38 39 if [ "" == "$files" ] ;then40 echo "usage :`basename $0` [-f hostfile] <from><to>"41 exit 242 fi43 44 for file in $files45 do46 if [ ! -f "$file" ] ;then47 echo "no hostfile file : $file"48 exit 249 fi50 51 hosts="$hosts `cat $file`"52 done53 54 for host in $hosts; do55 56 echo "send $sourcefiles to $host"57 58 echo "remote server url :/home/appuser/upload/$project/"59 60 scp -r $sourcefiles appuser@$host:/opt/app/webapps/$project/webapps/61 62 done63 64 exit

 

  • 这里要启动远程服务器的tomcat重启站点
#! /bin/shecho "call remote tomcat stop"hostfile=/opt/app/deploy/web/hostfilehosts=`cat $hostfile`for host in $hosts; dossh appuser@$host '/opt/app/bin/tomcat-web-stop.sh'echo "wait 5s for tomcat stop"sleep 5if [ $? -eq 0 ] ; then echo 'tomcat Stopped'ssh appuser@$host '/opt/app/bin/tomcat-web-start.sh'if [ $? -eq 0 ] ;thenecho "tomcat started"echo "wait 30s for tomcat starting"sleep 30# 查看是否已经启动url="http://$host:8091/status"echo "curl $url"curl $urlfifidoneexit $?