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

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

问题描述

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

上面的脚本只是打开cmd提示符并执行它.它没有获取执行的输出.即使执行失败,该阶段也显示为成功,并进入下一个阶段进行部署.我想开发它,以便 cmd 提示符中的输出应该被 Jenkins 当作输入,并且阶段应该继续.如果阶段在执行期间失败,阶段应该显示失败,如果执行成功,阶段应该在 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 行输出定向到 jenkins的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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