jenkins 构建 Unity3D输出log重定向

用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()

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值