jenkins - 是否可以从管道中的 sh DSL 命令捕获标准输出

标签 jenkins jenkins-workflow jenkins-pipeline

例如:

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

我会得到:

output=0

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

最佳答案

Nowsh step支持通过提供参数returnStdout返回stdout

// 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)

参见this example .

关于jenkins - 是否可以从管道中的 sh DSL 命令捕获标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36507410/

相关文章:

jenkins - 在 Jenkins office-365-connector-plugin 中使用宏

mysql - 与 eclipse 连接良好,但与 jenkins 抛出 com.mysql.cj.jdbc.exceptions.CommunicationsException : Communications link failure

java - 如何使用 Selenium Hub、Node 和 Remote Webdriver 捕获图像并将其附加到 Cucumber Reports (Jenkins)?

jenkins - 如何让 jenkins 使用 phantomjs 运行我的 qunit 测试

linux - 使用相同的配置和构建实现多个 jenkins

javascript - 如何使用Jenkins部署网站

jenkins - jenkins 管道脚本中的重复变更日志

jenkins - DSL 的管道源

macos - OS X 上的 Jenkins : xcodebuild gives Code Sign error

java - 如何向 Jenkins 提供依赖 JAR 来构建 Maven 项目?