https://gist.github.com/VladFrost/89e8ccabd40eb0f52374d7982>多行
步骤{echo '部署到临时环境'//启动tomcat蝙蝠"cd c:\qa\bin目录/a/b启动"蝙蝠"cd c:\qa\bin启动"//将 WAR 移动到 Tomcat 的代码bat "xcopy/y c:\webapp\target\webapp.war ...";bat "xcopy/y c:\webapp\target\webapp.war ...";}
示例:
调用批处理文件
如果您需要使用 jenkins 执行批处理文件:
stage('build') {目录(build_folder"){batrun_build_windows.bat"}}
或
stage('build') {batc://some/folder/run_build_windows.bat"}
Windows 路径有时很奇怪 :s .无论如何,Linux 是托管 jenkins 的最佳选择.
I'm trying to run a batchscript present inside the workspace of jenkins. I have written a groovy script as below to do this
stage('batchscript') {
steps{
bat 'start cmd.exe /c C:\Program Files (x86)\Jenkins\workspace\jenkins Project\batchfile.bat'
}
}
when I build the job it should open a new command window and run my batch file in a new command prompt executing all the bat commands. The build is succesful but no command window opens up. Any suggestion will be helpfull
解决方案
Jenkins is aimed to execute shell commands in background mode, not for interactive(UI) mode. When you run start cmd.exe /c c://some/app.exe
a new cmd UI is opened and this will never happen in jenkins.
Single line
If you need to execute a simple batch commands with jenkins :
stage('build') {
cmd_exec('echo "Buils starting..."')
cmd_exec('echo "dir /a /b"')
}
def cmd_exec(command) {
return bat(returnStdout: true, script: "${command}").trim()
}
Here a advanced example :
Multiline
steps {
echo 'Deploy to staging environment'
// Launch tomcat
bat """
cd c:\qa\bin
dir /a /b
startup
"""
bat """
cd c:\qa\bin
startup
"""
// Code to move WAR to Tomcat
bat "xcopy /y c:\webapp\target\webapp.war ..."
bat "xcopy /y c:\webapp\target\webapp.war ..."
}
Example:
Invoke batch file
If you need to execute a batch file with jenkins :
stage('build') {
dir("build_folder"){
bat "run_build_windows.bat"
}
}
or
stage('build') {
bat "c://some/folder/run_build_windows.bat"
}
这篇关于为什么我无法在 Windows 10 中运行的 jenkins 管道中运行批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!