windows 如何在詹金斯中运行bat文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48145057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:01:35  来源:igfitidea点击:

How to run bat file in jenkins

windowsbatch-filejenkinscmd

提问by Tatkal

My jenkins is installed in C:\Program Files (x86)\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. But when i try from jenkins executing batch command as mentioned in Image, Jenkins displays error as

当我从 cmd 运行这个 bat 文件时,一切正常。但是当我尝试从 jenkins 执行图像中提到的批处理命令时,Jenkins 显示错误为

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

构建步骤“执行 Windows 批处理命令”将构建标记为失败

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

同样在 jenkins 文件夹中,工作区文件夹会自动创建,并带有职位名称。你们能不能详细解释一下

回答by hopetds

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:\users\admin\workspace\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. By default in jenkins job you can access your workspace using $WORKSPACE variable

Jenkins 自动创建带有职位名称的文件夹,保存工作数据和其他构建信息......这就是它的工作原理。默认情况下,在 jenkins 工作中,您可以使用 $WORKSPACE 变量访问您的工作区

回答by CarlMc

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. 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 的工作方式是为每个作业创建自己的工作区,本质上是沙箱环境,它是一个测试框架,因此它应该用于对代码进行阶段性更改,然后将其推送到您的实时(工作)环境。人们使用它来自动化一些任务,但这不是 Jenkins 的主要用途。

回答by user5735673

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