问题
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