Executing Batch File in Jenkins

点点圈 提交于 2019-12-08 15:29:01

问题


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

Is there are plugin in Jenkins for the same ?

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


回答1:


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).




回答2:


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

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

While building the job the batch file will automatically executed.




回答3:


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

  • 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"

For example you can echo the systemdrive variable:

bat 'echo %systemdrive%'


来源:https://stackoverflow.com/questions/19020945/executing-batch-file-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!