Jenkins自动部署svn上去的selenium+python项目,执行报错找不到模块
在本地执行selenium成功,但是svn到Jenkins后,执行报错,找不到模块
具体日志如下:
Started by user admin Running as SYSTEM Building in workspace C:\Users\Administrator\.jenkins\workspace\shopsvn Updating svn://139.159.149.114/machong/Shop_V21 at revision '2022-03-05T10:55:40.882 +0800' --quiet Using sole credentials wuxx/****** in realm ‘<svn://139.159.149.114:3690> ea9421a4-a020-4eb3-a9d0-453ba536d2e5’ At revision 601 No changes for svn://139.159.149.114/machong/Shop_V21 since the previous build Script returned: [shopsvn] $ cmd /c call D:\soft\apache\apache-tomcat-9.0.54\temp\jenkins1865818149553420835.bat C:\Users\Administrator\.jenkins\workspace\shopsvn>cd runCases C:\Users\Administrator\.jenkins\workspace\shopsvn\runCases>python run.py Traceback (most recent call last): File "run.py", line 15, in <module> from shop_utils.email_manager import EmailManager ModuleNotFoundError: No module named 'shop_utils' C:\Users\Administrator\.jenkins\workspace\shopsvn\runCases>exit 1 Build step 'Execute Windows batch command' marked build as failure Sending e-mails to: 75603083@qq.com Finished: FAILURE
解决方法:
在每个调用找不到模块的py文件,最上面加上以下代码:
import sys
import os
#将项目路径加到环境变量里面
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.abspath(os.path.dirname(curPath) + os.path.sep + ".")
sys.path.append(rootPath)