如何将Cmd行输出定向到詹金斯 [英] How to Direct the Cmd line output to jenkins

查看:70
本文介绍了如何将Cmd行输出定向到詹金斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stage("execution") {
    Steps {
       bat 'start cmd.exe /c c:\\users\\doc\\sample.bat'
    }
}

上面的脚本只是打开cmd提示符并执行它.它不接受执行的输出.即使执行失败,该阶段也会显示为成功,并且将移至下一个部署阶段.我想开发它,以便Jenkins将cmd提示符中的输出作为输入,并且应该继续进行舞台.如果该阶段在执行期间失败,那么该阶段应该显示失败,如果执行成功,那么该阶段应该在Jenkins中显示成功.有人可以帮忙吗?

The above script is just opening the cmd prompt and executing it. It's not taking the output of the execution. Even if the execution fails, the stage is shown as successful and it moves to the next stage for deployment. I want to develop it so that the output in the cmd prompt should be taken as input by Jenkins and stage should go on. If the stage fails during execution, the stage should show failure and if the execution succeeds, the stage should show success in Jenkins. Can anyone help?

另一个问题:如果批处理文件位于Git中,如何在上述脚本中给出路径?

Another question: If the batch file is located in Git, how to give the path in the above script?

推荐答案

使用start命令,您正在创建Jenkins无法跟踪的新的独立控制台进程.

Using the start command, you are creating a new detached console process which Jenkins cannot keep track of.

改为这样做:

bat 'call "c:\\users\\doc\\sample.bat"'

这将在与当前脚本相同的环境中运行该批处理文件,并等待该批处理文件结束. Jenkins将能够捕获标准输出并通过批处理文件的退出代码检测错误.

This runs the batch file in the same environment as the current script and waits for the batch file to end. Jenkins will be able to capture the standard output and detect errors through the exit code of the batch file.

您可以编写@call以便从输出中隐藏命令行.

You may write @call to hide the command-line from the output.

这篇关于如何将Cmd行输出定向到詹金斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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