第一步:我使用下面提到的命令创建了一个BAT文件并尝试运行它>它确实运行了我已经配置的所有测试的TestNG Suite。
下一步:设置Jenkins我试图使用添加构建设置>执行Windows bat命令>来运行bat文件
cd /d %~dp0
set classpath=bin;lib\*;lib\selenium\*;lib\POI\*;bin\com\healthcare\*;bin\com\healthcare\reports\*;
java org.testng.TestNG Smoke_OrderIDCards.xml
并且
run smoke.bat
具有上述所有命令
还有
call %WORKSPACE%\smoke.bat
并且
run %WORKSPACE%\smoke.bat
它一直在詹金斯控制台中抛出错误:
[Purchaser] $ cmd /c call /proj/jenkins/tmp/jenkins9142107435735320094.bat
FATAL: command execution failed
java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:248)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
Caused: java.io.IOException: Cannot run program "cmd" (in directory "/proj/jenkins/workspace/Purchaser"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:245)
at hudson.Proc$LocalProc.<init>(Proc.java:214)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:850)
at hudson.Launcher$ProcStarter.start(Launcher.java:384)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:735)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:490)
at hudson.model.Run.execute(Run.java:1735)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:405)
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
但我想如果它运行的服务器是什么,不是Windows并尝试通过Add Build Step > Execute Shell
运行示例命令
以echo $WORKSPACE
命令,这是成功的。我试着在任何地方查找,以便通过shell脚本完成相同的操作并且无法完成。
现在我需要知道如何通过shell命令运行我在(set classpath and run the TestNG.xml file)
上面提到的相同命令。有人可以帮我解决这个问题吗?
cd $WORKSPACE
java -cp "lib/*:lib/selenium/*:lib/POI/*:bin:" org.testng.TestNG $WORKSPACE/Smoke_OrderIDCards.xml
我在上面提到了link来设置classpath语法。
这是我在Jenkins配置的Execute Shell Command字段中给出的命令,它确实有效!