python:无法打开文件“ MainRunner.py”:[Errno 2] jenkins中没有此类文件或目录

时间:2019-06-26 10:45:52

标签: python batch-file jenkins

我正在尝试在jenkins版本的Windows批处理文件中运行自动化测试。它被设置为定期从gitlab中获取源代码,现在我正尝试对其进行配置以运行我的自动化测试框架。

我遇到的问题是以下错误: python:无法打开文件'MainRunner.py':[Errno 2]没有这样的文件或目录

我意识到,此问题通常是由于找不到文件所在的错误文件夹或文件权限错误引起的。

这是Windows批处理脚本:

echo "begining build"
icacls * /reset /t /c /q 
pip freeze > requirements.txt
echo "executing unit tests"
cd Test\unit\
dir
python MainRunner.py
python TestDrive.py
echo "build complete"

和输出:

02:00:29 [Financial-Application] $ cmd /c call "C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp\jenkins9213047334246424605.bat"
02:00:29 
02:00:29 C:\Windows\system32\config\systemprofile\.jenkins\workspace\Financial-Application>echo "begining build" 
02:00:29 "begining build"
02:00:29 
02:00:29 C:\Windows\system32\config\systemprofile\.jenkins\workspace\Financial-Application>icacls * /reset /t /c /q  
02:00:29 Successfully processed 589 files; Failed processing 0 files
02:00:29 
02:00:29 C:\Windows\system32\config\systemprofile\.jenkins\workspace\Financial-Application>pip freeze  1>requirements.txt 
02:00:30 
02:00:30 C:\Windows\system32\config\systemprofile\.jenkins\workspace\Financial-Application>echo "executing unit tests" 
02:00:30 "executing unit tests"
02:00:30 
02:00:30 C:\Windows\system32\config\systemprofile\.jenkins\workspace\Financial-Application>cd Test\unit\ 
02:00:30 
02:00:30 C:\Windows\System32\config\systemprofile\.jenkins\workspace\Financial-Application\Test\unit>dir
02:00:30  Volume in drive C has no label.
02:00:30  Volume Serial Number is 0219-9097
02:00:30 
02:00:30  Directory of C:\Windows\System32\config\systemprofile\.jenkins\workspace\Financial-Application\Test\unit
02:00:30 
02:00:30 06/25/2019  02:00 AM    <DIR>          .
02:00:30 06/25/2019  02:00 AM    <DIR>          ..
02:00:30 06/25/2019  02:00 AM             2,164 .coverage
02:00:30 06/14/2019  05:58 AM    <DIR>          data
02:00:30 06/14/2019  05:58 AM               693 MainRunner.py
02:00:30 06/22/2019  02:00 AM             2,624 TestDrive.py
02:00:30 06/22/2019  02:00 AM             7,316 TestSpreadsheet.py
02:00:30 06/25/2019  02:00 AM             9,652 TestWorksheet.py
02:00:30                5 File(s)         22,449 bytes
02:00:30                3 Dir(s)  1,069,314,711,552 bytes free
02:00:30 
02:00:30 C:\Windows\System32\config\systemprofile\.jenkins\workspace\Financial-Application\Test\unit>python MainRunner.py 
02:00:30 python: can't open file 'MainRunner.py': [Errno 2] No such file or directory
02:00:30 
02:00:30 C:\Windows\System32\config\systemprofile\.jenkins\workspace\Financial-Application\Test\unit>python TestDrive.py 
02:00:30 python: can't open file 'TestDrive.py': [Errno 2] No such file or directory
02:00:30 
02:00:30 C:\Windows\System32\config\systemprofile\.jenkins\workspace\Financial-Application\Test\unit>echo "build complete" 
02:00:30 "build complete"
02:00:30 
02:00:30 C:\Windows\System32\config\systemprofile\.jenkins\workspace\Financial-Application\Test\unit>exit 2 
02:00:30 Build step 'Execute Windows batch command' marked build as failure
02:00:31 Build did not succeed and the project is configured to only push after a successful build, so no pushing will occur.
02:00:31 Finished: FAILURE

如您所见,我进入相应的文件夹并运行DIR命令并找到了文件。这样就留下了文件权限。我不知道是否有一种特殊的方法来修改jenkins中的权限,但是我确实确保了工作区文件系统中jenkins中的实际文件夹具有读/写/执行权限。

我还运行ICACLS命令尝试修复文件权限,但这似乎无济于事。

0 个答案:

没有答案