是否可以从管道中的 sh DSL 命令捕获标准输出 [英] Is it possible to capture the stdout from the sh DSL command in the pipeline

查看:28
本文介绍了是否可以从管道中的 sh DSL 命令捕获标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

var output=sh "echo foo";
echo "output=$output";

我会得到:

output=0

所以,显然我得到的是退出代码而不是标准输出.是否可以将标准输出捕获到管道变量中,以便我可以获得:output=foo作为我的结果?

So, apparently I get the exit code rather than the stdout. Is it possible to capture the stdout into a pipeline variable, such that I could get: output=foo as my result?

推荐答案

现在sh step 通过提供参数 returnStdout 支持返回 stdout.

Now, the sh step supports returning stdout by supplying the parameter returnStdout.

// These should all be performed at the point where you've
// checked out your sources on the slave. A 'git' executable
// must be available.
// Most typical, if you're not cloning into a sub directory
gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
// short SHA, possibly better for chat notifications, etc.
shortCommit = gitCommit.take(6)

请参阅此示例.

这篇关于是否可以从管道中的 sh DSL 命令捕获标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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