10

My jenkins is installed in C:\Program Files (x86)\Jenkins

bat file is located in C:\Users\Admin\workspace\demoWork\run.bat

When i run this bat file from cmd everything works fine. But when i try from jenkins executing batch command as mentioned in Image, Jenkins displays error as

Build step 'Execute Windows batch command' marked build as failure

enter image description here

Also inside jenkins folder automatically workspace folder gets created with Job title name. Can you guys please explain me in detail

Tatkal
  • 568
  • 4
  • 9
  • 29

3 Answers3

11

Tatkal, you can't execute a command like in your image,

why don't you simply try

C:\users\admin\workspace\demowork\run.bat

or

call "C:\users\admin\workspace\demowork\run.bat"

"Also inside jenkins folder automatically workspace folder gets created with Job title name. Can you guys please explain me in detail" -

Jenkins creates folder with job title name automatically, saves jobs data and other build info... this is how it works. By default in jenkins job you can access your workspace using $WORKSPACE variable

hopetds
  • 435
  • 2
  • 6
  • Bro i tried as you mentioned above...It works fine....But right now I am stuck with this error "Process leaked file descriptors. See jenkins.io/redirect/troubleshooting/… for more information" and tried everything.....but nothing seems working – Tatkal Jan 08 '18 at 13:23
  • please,post jenkins log after executing your batch file... we'll figure it out why its failing – hopetds Jan 08 '18 at 14:31
  • your batch script leaves processes after running successfully? if so- it might be a problem – hopetds Jan 08 '18 at 14:38
  • java.lang.Exception at hudson.Proc$LocalProc.join(Proc.java:334) at hudson.tasks.CommandInterpreter.join(CommandInterpreter.java:155) 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:744) at hudson.model.Build$BuildExecution.build(Build.java:206) at hudson.model.Build$BuildExecution.doRun(Build.java:163) – Tatkal Jan 09 '18 at 05:38
  • @Tatkal, what exactly your batch script does? It seems like jenkins cant exit build step normally, so i suggest you to add exit codes in your batch file. ex: exit 0 if everything is ok, exit 1 if not. – hopetds Jan 09 '18 at 08:11
  • @hopteds please let me know exactly where to place these exit codes. My batch script just starts my bat file which in turn starts my application. – Tatkal Jan 09 '18 at 08:34
  • @Tatkal, i cant tell you for a 100%, can't check it right now, but as far as i remember you can test your last exit code like this Insert this code after launching your application in batch, for ex: app.exe if %ERRORLEVEL% EQU 0 ( echo Success exit 0 ) else ( echo error: %errorlevel% exit 1 exit /b %errorlevel% ) – hopetds Jan 09 '18 at 08:50
  • @hopetds...I am using jenkins in Windows server – Tatkal Jan 09 '18 at 08:52
  • @Tatkal, so, whats the difference?Again, it seems like the problem is that jenkins cant finish build step with your "run windows batch command" because of the new process/processes that script starts. And you should manually tell jenkins what to do if your batch script finished its work properly or not. – hopetds Jan 09 '18 at 08:59
3

You have put very little detail into this so I'm going by pure guess..

The Execute Windows batch command is to literally execute code, not execute a file.. to execute the file you could use this command :

start cmd.exe /c C:\myprj\mybat.bat

or you could take the contents of the .bat file and rewrite in in that command line..

The way Jenkins works is it creates its own workspace for each job, essentially to sandbox the environment, its a testing framework so it should be used to stage changes to code, which will then be pushed to your live(working) environment. People use it to automate some tasks, but this isnt the primary use of Jenkins.. if the above doesn't help you let me know more details of the error and I can try help you with it.

CarlMc
  • 210
  • 2
  • 11
  • edited- it was the part in the quotes I want'ed you to run – CarlMc Jan 08 '18 at 10:43
  • Process leaked file descriptors. See https://jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors for more information................While running other jobs, I'm getting the same error – Tatkal Jan 08 '18 at 10:49
  • have a look here - https://stackoverflow.com/questions/17024441/process-leaked-file-descriptors-error-on-jenkins especially if you're having the same issue in other jobs. – CarlMc Jan 08 '18 at 10:50
  • You will need to expand on your above issue then, theres not enough information to help you – CarlMc Jan 08 '18 at 13:02
2
node {
   bat 'D:\\gatling-charts-highcharts-bundle-3.0.2\\bin\\gatling.bat'
}