无法使用Jenkins执行git repo中提交的代码的TestNG.xml

问题描述

@H_502_0@我正在尝试使用TestNG.xml通过Jenkins执行我的Selenium项目代码。我能够使用maven通过Jenkins成功运行代码,但是现在我想设置构建,以便可以使用testNG.xml文件运行相同的代码。为此

  1. 我将jenkins中的New项目设置为Freestyle项目(即使我的项目是maven项目)。
  2. 我向项目中添加一个批处理文件,其内容如下
@H_502_0@ java org.testng.TestNG testngscripts.xml 暂停

@H_502_0@ testng罐子位于我的mvn依赖文件夹中。但是我认为,自从我创建为自由项目以来,它没有被读取,并且在执行构建后,jenkins出现以下错误

*> git.exe fetch --tags --force --progress -- https://github.com/uppalvishal/SeleniumMockProject.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision 703b73fd5b9fde5404b52d2caa3f8c4769554291 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f 703b73fd5b9fde5404b52d2caa3f8c4769554291 # timeout=10
Commit message: "committed batch file"
First time build. Skipping changelog.
[Selenium_Automation_TestNG] $ cmd /c call C:\Users\vuppal\AppData\Local\Temp\jenkins2717609267405812765.bat
C:\Users\vuppal\.jenkins\workspace\Selenium_Automation_TestNG>testngBatchFile.bat
**C:\Users\vuppal\.jenkins\workspace\Selenium_Automation_TestNG>java org.testng.TestNG testng.xml 
Error: Could not find or load main class org.testng.TestNG
Caused by: java.lang.classNotFoundException: org.testng.TestNG**
C:\Users\vuppal\.jenkins\workspace\Selenium_Automation_TestNG>pause
Press any key to continue . . . 
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE*
@H_502_0@我什至尝试通过在项目中创建一个lib文件夹并将批处理文件更改为

来放置testng jars @H_502_0@ java -cp lib * org.testng.TestNG testngscripts.xml 暂停

@H_502_0@,还有github代码中lib文件夹的完整路径,例如

@H_502_0@ java -cp https://github.com/uppalvishal/SeleniumMockProject/tree/master/lib org.testng.TestNG testngscripts.xml

@H_502_0@我的问题是如何在类路径中获取此类org.testng.TestNG,以便Jenkins可以执行我的testNG xml文件

解决方法

pom.xml中是否存在TestNG Jar?您在使用Maven吗?

您需要为此使用maven。 将您的TestNG jar依赖项放入Maven并上传到GIT 从GIT下载项目后,Maven将自动下载TestNG jar。 这样很好用