为什么我无法在Windows 10中运行的jenkins管道中运行批处理文件? [英] why am I not able to run batch file in jenkins pipeline running in windows 10?

查看:791
本文介绍了为什么我无法在Windows 10中运行的jenkins管道中运行批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行jenkins工作区中存在的批处理脚本.我已经编写了如下的groovy脚本

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'\
}
}

构建作业时,它应该打开一个新的命令窗口,并在执行所有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旨在在后台模式下执行shell命令,而不是在 interactive 模式下执行.

Jenkins is aimed to execute shell commands in background mode, not for interactive mode.

如果您需要使用jenkins执行简单的批处理命令:

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()
}

这是一个高级示例:

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 ..."
}

示例:

如果您需要使用jenkins执行批处理文件:

If you need to execute a batch file with jenkins :

stage('build') {
  dir("build_folder"){
      bat "run_build_windows.bat"
  }
}

stage('build') {
  bat "c://some/folder/run_build_windows.bat"
}

Windows路径有时是奇怪的:s.无论如何,Linux是托管jenkins的最佳选择.

Windows paths some time are bizarre :s . Anyway, linux is the best choice to host jenkins.

这篇关于为什么我无法在Windows 10中运行的jenkins管道中运行批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆