How to run bat file in jenkins

2020-06-17 06:42发布

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

3条回答
贪生不怕死
2楼-- · 2020-06-17 06:52

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

查看更多
▲ chillily
3楼-- · 2020-06-17 06:59
node {
   bat 'D:\\gatling-charts-highcharts-bundle-3.0.2\\bin\\gatling.bat'
}
查看更多
成全新的幸福
4楼-- · 2020-06-17 07:14

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.

查看更多
登录 后发表回答