jenkins 構建 Unity3D輸出log重定向
阿新 • • 發佈:2019-01-26
用jenkins構建Unity3D的時,在jenkins上就看不到任何構建日誌的。所以做了這個指令碼,把Unity3D的構建日誌重定向
到jenkins中.在打包指令碼中加上RedirectUnityOut.py 就行了。
RedirectUnityOut.py
使用方法:RedirectUnityOut.py [Unity.exe] [Unity 構建引數]
RedirectUnityOut.py D:\Unity\Editor\Unity.exe -quit -batchmode -projectPath ProjectPath -executeMethod TestMethod
#!/usr/bin/python # -*- coding: utf-8 -*- import os,sys,string,datetime,time,threading g_bStop = False class OutputLogThread(threading.Thread): m_logFilePath = '' def run(self): global g_bStop nPosRead = 0 fp = None print 'OutputLogThread Start' while g_bStop == False: if os.path.isfile(self.m_logFilePath): if fp == None: fp = open(self.m_logFilePath, 'r') if fp != None: fp.seek(nPosRead) allLines = fp.readlines() nPosRead = fp.tell() fp.close() fp = None for lines in allLines: print lines time.sleep(0.5) def __init__(self, logPath): threading.Thread.__init__(self) self.m_logFilePath = logPath if __name__ == '__main__': if len(sys.argv) < 2: print 'not find unity path' sys.exit(-1) logFilePath = 'editor.txt' unityRunParm = '' for i in range(len(sys.argv)): if i > 0: unityRunParm += ' ' + sys.argv[i] unityRunParm += ' -logfile ' + logFilePath if os.path.isfile(logFilePath): os.remove(logFilePath) logThread = OutputLogThread(logFilePath) logThread.start() os.system(unityRunParm) g_bStop = True logThread.join()