詹金斯(Jenkins)构建时如何禁用tomcat日志输出?

时间:2018-12-24 03:40:17

标签: jenkins tomcat7

我正在用jenkins构建项目。最后一步,我使用python启动了tomcat服务器。但是jenkins不断在其控制台上输出tomcat的日志,这种构建永远不会成功。 然后我去看服务器,机器上没有tomcat窗口,而是Windows Task Manager中的一个进程。

有人可以帮我解决问题吗?谢谢。 我的python代码如下:

    def StartServer():
            execu = os.path.join(tomcat_dir,'bin','startup.bat')
            logger.info(execu)
            os.chdir(os.path.join(tomcat_dir,'bin'))
            os.system('.\startup.bat')
            logger.info('Tomcat started.')

1 个答案:

答案 0 :(得分:0)

查看此内容:

#!/usr/bin/python
import os
from commands import getstatusoutput as loc
opt,aloc,mloc,adown,mdown, = '','','','',''
# Enter your default Tomcat BIN Directory
Default='NULL' #TomcatDefault
def search():
    global aloc, mloc, adown, mdown
    os.system('sudo updatedb')
    aloc=loc('locate tomcat | grep /opt | grep startup.sh')
    adown=loc('locate tomcat | grep /opt | grep shutdown.sh')
    mloc=loc('locate tomcat | grep /usr | grep startup.sh')
    mdown=loc('locate tomcat | grep /usr | grep shutdown.sh')



def restart(op):

    global aloc, mloc, adown, mdown, Default
    if op == 'aloc':
        try:
            print("Shuting Down Tomcat")
            os.system('sudo {0}'.format(adown[1]))
            except OSError as err:
            print("Error Shutting : {0}".format(err))
            os.system("sudo kill -9 `ps aux |grep tomcat | awk '{print $2}'`")
            print("Killing Tomcat....")
            os.system('sleep 2')
        try:
            print("Starting Tomcat")
                os.system('sudo {0}'.format(aloc[1]))
        except OSError as err:
            print("Error Starting : {0}".format(err))

    elif op == 'mloc':
        try:
                        print("Shuting Down Tomcat")
                        os.system('sudo {0}'.format(mdown[1]))
                except OSError as err:
                        print("Error Shutting : {0}".format(err))
            os.system("sudo kill -9 `ps aux |grep tomcat | awk '{print $2}'`")
            print("Killing Tomcat....")
            os.system('sleep 2')
                try:    
                        print("Starting Tomcat")
                        os.system('sudo {0}'.format(mloc[1]))
                except OSError as err:
                        print("Error Starting : {0}".format(err))

    elif op == 'Default':
        try:
                        print("Shuting Down Tomcat")
                        os.system('sudo {0}shutdown.sh'.format(Default))
                except OSError as err:
                        print("Error Shutting : {0}".format(err))
            os.system("sudo kill -9 `ps aux |grep tomcat | awk '{print $2}'`")
            print("Killing Tomcat....")
            os.system('sleep 2')
                try:    
                        print("Starting Tomcat")
                        os.system('sudo {0}startup.sh'.format(Default))
                except OSError as err:
                        print("Error Starting : {0}".format(err))




def choice():
    global opt, aloc, mloc
    if aloc[0] == 0 and mloc [0] == 0:
        opt=raw_input("Choose Tomcat version :\n1.\t{0}\n2.\t{1}\n\t".format(aloc,mloc))

def main():
    global Default, aloc,mloc,opt
    if Default == 'NULL':
            search()
            choice()
            if opt == '1' or mloc[0] != 0:
                restart('aloc')
                exit(0)
            elif opt == '2' or aloc[0] != 0:
                restart('mloc')
                exit(0)
            else:
                print("Invalid Choice\nEnter Again")
                main()
    else:
        restart('Default')
        exit(0)

main()

我看到了这个github link