</pre>基于眼下业务的版本号。使用的maven 及tomcat <p></p><p>假设我们使用 Jenkins 公布是比較好的,可是存在一定的问题,就是须要学习时间,</p><p>基于我们的项目。我使用python 自己主动构建公布环境</p><p>脚本例如以下:</p><p></p><pre code_snippet_id="498203" snippet_file_name="blog_20141027_2_7484436" name="code" class="python">#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import ConfigParser
homedir = os.getcwd()
print homedir
config = ConfigParser.ConfigParser()
config.read("config.propties")
user_name = config.get("SVN", "user_name").decode('utf8').encode('cp936')
user_password = config.get("SVN", "user_password").decode('utf8').encode('cp936')
check_out_dir = homedir
log_name = config.get("SVN", "log_name").decode('utf8').encode('cp936')
script_dir = homedir
pkg_name=homedir+os.path.sep+"mabaobang-web"+os.path.sep+"target"+os.path.sep+"mabaobang-web.war"
rmote_ip=config.get("SVN", "rmote_ip")
rmote_user=config.get("SVN", "rmote_user")
rmote_passwd=config.get("SVN", "rmote_passwd")
print "pkg_name",pkg_name
script_dir=config.get("SVN", "script_dir").decode('utf8').encode('cp936')
command = "svn log -v --xml " + check_out_dir + " > " + log_name + " --username " + user_name + " --password " + user_password
os.system( command )
os.chdir(check_out_dir)
print os.path.abspath(".").decode('cp936').encode('utf8')
command1="svn update "+ check_out_dir + " --username " + user_name + " --password " + user_password +" --no-auth-cache --non-interactive --trust-server-cert"
os.system( command1 )
os.system("mvn clean:clean package");
file_object = open('123123.txt', 'w')
file_object.write("open 192.168.15.234
")
file_object.writelines("put "+pkg_name+"
")
#file_object.writelines(file.newlines)
file_object.writelines("bye
")
#file_object.writelines(file.newlines)
#file_object.writelines(file.newlines)
file_object.flush()
file_object.close()
if os.path.exists(pkg_name):
os.chdir(homedir)
try:
command_sftp="ftp.exe -l "+ rmote_user +" -pw "+rmote_passwd+" -b 123123.txt "
os.system( command_sftp )
except Exception,e:
print "done"
finally:
command_ssh="ssh.exe -ssh -pw "+ rmote_passwd +" "+rmote_passwd+ "@192.168.15.234 '/home/momabo/deploy.sh' "
os.system( command_ssh )
配置文件例如以下:
[SVN] user_name=111111 user_password=000000 #check_out_dir=D:111111111-parent log_name=E:log.log #out_put_dir=D:1111111-parent #war_name=D:11111111-parent11111111111111-web arget111111111-web.war rmote_ip=192.168.15.234 rmote_user=xxxx须要二个开源软sftp.exe http://the.earth.li/~sgtatham/putty/0.63/x86/psftp.exe
和 ssh.exe http://the.earth.li/~sgtatham/putty/0.63/x86/plink.exe 进行下载后就能够了
自己主动化公布后台脚本
!/bin/bash ###?碌?梅?
猫?陋掳????娄碌?war路?碌陆录?
?驴?
录???忙 ###碌??禄虏陆拢潞录矛虏茅?
??
娄碌?
掳眉??路帽??麓芦碌陆录??驴?录??
拢潞 USER_HOME=/home/3213123 TOMCAT_HOME=${USER_HOME}/tomcat #?娄??碌??
驴?录 APP_HOME=${TOMCAT_HOME}/webapps/12313123-web CONF_FILE=${APP_HOME}/WEB-INF/classes/config.properties IP_ADD=127.0.0.1 MYSQL_USER_NAME=root MYSQL_USER_PASSWD=213131 UPLOAD_DIR=/home/312312312/upload ###碌?
?禄虏陆拢潞录矛虏茅?
?
?
娄碌?掳眉?
?路帽??麓芦碌陆录?
?
驴?录??拢潞 if [ ! -f ${USER_HOME}/mabaobang-web.war ];then echo -e "