windows 在 Jenkins 中执行批处理文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19020945/
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-09 10:55:28  来源:igfitidea点击:

Executing Batch File in Jenkins

windowsjenkinsjenkins-plugins

提问by bhargav

I have a simple batch file. I want to call/run/execute that file from Jenkins.

我有一个简单的批处理文件。我想从 Jenkins 调用/运行/执行该文件

Is there are plugin in Jenkins for the same ?

Jenkins 中是否有相同的插件?

How can execute the batch file from Jenkins ? If there is any tutorial or documentation for the same.

如何从 Jenkins 执行批处理文件?如果有任何相同的教程或文档。

采纳答案by Mirko Ebert

On Linux, go to your jenkins job, go to configuration, add build step "execute shell", then type the name of your script. Please be sure that your file is executable (chmod 777 yourscript.sh) and in the right place (checkout via GIT or SVN, please check your job workspace, your current dir for execute is the job dir, base of job workspace) and to have a valid shebang (first line in your script file e.g. #!/bin/sh).

在 Linux 上,转到您的 jenkins 作业,转到配置,添加构建步骤“执行 shell”,然后键入脚本的名称。请确保您的文件是可执行的 (chmod 777 yourscript.sh) 并且在正确的位置(通过 GIT 或 SVN 签出,请检查您的作业工作区,您当前的执行目录是作业目录,作业工作区的基础)并有一个有效的shebang(脚本文件中的第一行,例如#!/bin/sh)。

回答by Sumeshk

No need to add a new plugin for that, in Jenkins, select your job name and go to the configure section.

无需为此添加新插件,在Jenkins 中,选择您的作业名称并转到配置部分

There is a Build section, on that section there is a combo box, select Execute windows Batch commandon that text box you can specify either the batch file details directly or specify the file path.

有一个Build 部分,在该部分有一个组合框,在该文本框中选择Execute windows Batch 命令,您可以直接指定批处理文件详细信息或指定文件路径。

While building the job the batch file will automatically executed.

在构建作业时,批处理文件将自动执行。

回答by Slava Babin

If you are using Jenkins Pipeline, you can simply use batstep. You can generate Groovy by clicking "Pipeline Syntax".

如果您使用的是 Jenkins Pipeline,则可以简单地使用batstep。您可以通过单击“管道语法”来生成 Groovy。

  • Go to your pipeline and click "Configure"
  • Go to the bottom and under pipeline script click"Pipeline Syntax"
  • Choose Sample Step - "Windows Batch Script"
  • Enter your Batch Script and click "Generate Groovy"
  • 转到您的管道并单击“配置”
  • 转到底部并在管道脚本下单击“管道语法”
  • 选择示例步骤 - “Windows 批处理脚本”
  • 输入您的批处理脚本并单击“生成 Groovy”

Jenkins snippet generator

詹金斯片段生成器

For example you can echo the systemdrive variable:

例如,您可以回显 systemdrive 变量:

bat 'echo %systemdrive%'