Issue
First Step: I created a BAT File with below mentioned commands and tried running it > It did successfully run the TestNG Suite with all the tests I had configured.
Next Step: was to set up the Jenkins I was trying to run the bat file with the Add build setup > execute Windows bat command >
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
And also
run smoke.bat
which has all the above commands
And also with
call %WORKSPACE%\smoke.bat
and also
run %WORKSPACE%\smoke.bat
it kept throwing the error in Jenkins console as:
[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
But I figured what if the server it's running on, is not Windows and tried running a sample command through Add Build Step > Execute Shell
with the command as echo $WORKSPACE
and that was a success. And I tried looking up everywhere I could to finout how to do the same through shell script and was not able to.
Now I need to know how to run the same commands I mentioned above (set classpath and run the TestNG.xml file)
through shell commands. Could someone help me with this problem?
Solution
cd $WORKSPACE
java -cp "lib/*:lib/selenium/*:lib/POI/*:bin:" org.testng.TestNG $WORKSPACE/Smoke_OrderIDCards.xml
I referred to the link for setting classpath syntax as above.
This is the command I have given in the Execute Shell Command field for the Jenkins Configuration and it did work!
Answered By - S K