如何从Jenkinsfile(groovy)的变量中获取使用执行的Shell命令的输出? [英] How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?
本文介绍了如何从Jenkinsfile(groovy)的变量中获取使用执行的Shell命令的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Jenkinsfile(Groovy)上有类似的内容,我想将stdout和退出代码记录在一个变量中,以便以后使用该信息.
I have something like this on a Jenkinsfile (Groovy) and I want to record the stdout and the exit code in a variable in order to use the information later.
sh "ls -l"
我该怎么做,尤其是似乎不能在Jenkinsfile
内部真正运行任何常规代码吗?
How can I do this, especially as it seems that you cannot really run any kind of groovy code inside the Jenkinsfile
?
推荐答案
最新版本的管道sh
步骤允许您执行以下操作;
The latest version of the pipeline sh
step allows you to do the following;
// Git committer email
GIT_COMMIT_EMAIL = sh (
script: 'git --no-pager show -s --format=\'%ae\'',
returnStdout: true
).trim()
echo "Git committer email: ${GIT_COMMIT_EMAIL}"
另一个功能是returnStatus
选项.
// Test commit message for flags
BUILD_FULL = sh (
script: "git log -1 --pretty=%B | grep '\\[jenkins-full]'",
returnStatus: true
) == 0
echo "Build full flag: ${BUILD_FULL}"
这些选项是根据此问题添加的.
These options where added based on this issue.
请参见官方文档 sh
命令.
这篇关于如何从Jenkinsfile(groovy)的变量中获取使用执行的Shell命令的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文