Created
July 21, 2015 08:54
-
-
Save lhcpig/10de571c0fbf983c3319 to your computer and use it in GitHub Desktop.
script-tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
__author__ = 'lhcpig' | |
import sys | |
import os | |
gitDir = "/home/git/repositories/test.git" | |
deployLogPath = "/home/lhcpig/deploy.log" | |
tomcatPath = "/this/is/tomcat" | |
workTree = "/home/lhcpig/projectName" | |
if __name__ == '__main__': | |
if len(sys.argv) <= 1: | |
print("请输入需要部署的分支") | |
exit(0) | |
branchList = [x for x in os.listdir(gitDir+"/refs/heads")] | |
with open(deployLogPath, "w") as logFile: | |
for branch in sys.argv[1:]: | |
if branch in branchList: | |
if branch.startswith("xy"): | |
module = "moduleName" | |
warName = "hello" | |
else: | |
logFile.write("branch is exists, but i do not know where to deploy." + "\n") | |
continue | |
else: | |
logFile.write("unknown branch:" + branch + "\n") | |
continue | |
os.system( | |
"git" | |
" --work-tree=" + workTree + | |
" --git-dir=" + gitDir + | |
" checkout " + branch + " -f") | |
os.chdir(workTree) | |
os.system("mvn clean package -pl " + module + " -am -DskipTests -Ptest") | |
warFrom = workTree + module + "/target/" + module + ".war" | |
warTo = tomcatPath + "/webapps/" + warName + ".war" | |
if os.path.isfile(warFrom): | |
os.rename(warFrom, warTo) | |
logFile.write("build success:" + branch + "\n") | |
else: | |
print(warFrom + " do not exists.") | |
logFile.write("build fail!!!:" + branch + "\n") | |
os.chdir(gitDir) | |
os.system("git symbolic-ref HEAD refs/heads/master") | |
os.system("cat "+deployLogPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment