简体   繁体   English

如何在jenkins中运行bat文件

[英]How to run bat file in jenkins

My jenkins is installed in C:\\Program Files (x86)\\Jenkins 我的jenkins安装在C:\\Program Files (x86)\\Jenkins

bat file is located in C:\\Users\\Admin\\workspace\\demoWork\\run.bat bat文件位于C:\\Users\\Admin\\workspace\\demoWork\\run.bat

When i run this bat file from cmd everything works fine. 当我从cmd运行这个bat文件时一切正常。 But when i try from jenkins executing batch command as mentioned in Image, Jenkins displays error as 但是,当我尝试从图像中提到的jenkins执行批处理命令时,Jenkins显示错误为

Build step 'Execute Windows batch command' marked build as failure 构建步骤'执行Windows批处理命令'将构建标记为失败

在此输入图像描述

Also inside jenkins folder automatically workspace folder gets created with Job title name. 同样在jenkins文件夹中,自动工作区文件夹将使用作业标题名称创建。 Can you guys please explain me in detail 你们能详细解释一下我吗?

Tatkal, you can't execute a command like in your image, Tatkal,你不能像你的图像那样执行命令,

why don't you simply try 你为什么不试试呢

C:\\users\\admin\\workspace\\demowork\\run.bat C:\\用户\\ ADMIN \\工作区\\ demowork \\的run.bat

or 要么

call "C:\\users\\admin\\workspace\\demowork\\run.bat" 调用“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文件夹里面自动创建工作区文件夹,用作业标题名称创建。你们可以详细解释一下” -

Jenkins creates folder with job title name automatically, saves jobs data and other build info... this is how it works. Jenkins自动创建具有职位名称的文件夹,保存职位数据和其他构建信息......这就是它的工作原理。 By default in jenkins job you can access your workspace using $WORKSPACE variable 默认情况下,在jenkins作业中,您可以使用$ WORKSPACE变量访问工作区

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 : 执行Windows批处理命令是字面上执行代码,而不是执行文件..执行文件您可以使用此命令:

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

or you could take the contents of the .bat file and rewrite in in that command line.. 或者您可以获取.bat文件的内容并在该命令行中重写。

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. Jenkins的工作方式是为每个作业创建自己的工作区,主要是为沙箱环境,它是一个测试框架,因此它应该用于对代码进行更改,然后将其推送到您的实时(工作)环境。 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. 人们使用它来自动执行某些任务,但这不是Jenkins的主要用途..如果上述内容无法帮助您让我知道错误的更多细节,我可以尝试帮助您。

node {
   bat 'D:\\gatling-charts-highcharts-bundle-3.0.2\\bin\\gatling.bat'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM