如何在jenkins管道控制台输出中抑制源脚本行回显?

时间:2016-04-29 21:16:03

标签: jenkins groovy jenkins-pipeline

我正在Jenkins中编写一个管道作业,它显示管道控制台输出中下游作业的输出控制台。到目前为止工作正在进行,但由于管道作业本身将所有回声线添加到输出中,因此输出很难读取。

Started by user john.doe@cdf.com
[Pipeline] Allocate node : Start
Running on swqa-pr-prod-slave-1 in /srv/jenkins-slave/workspace/UUT Automated Regression - 1.20
[Pipeline] node {
[Pipeline] echo

[Pipeline] echo
/////////////////////////////////////////////////
[Pipeline] echo
                Start Execution                  
[Pipeline] echo
/////////////////////////////////////////////////
[Pipeline] echo

[Pipeline] echo

[Pipeline] [monitor] echo
[monitor] [EnvInject] - Loading node environment variables.
[Pipeline] [monitor] echo
[monitor] Building remotely on swqa-pr-prod-slave-1 (pr-prod-linux-slaves) in workspace /srv/jenkins-slave/workspace/Process Map Components Lock Down - 1.00
[Pipeline] [monitor] echo
[monitor] [EnvInject] - Injecting environment variables from a build step.
[Pipeline] [monitor] echo
[monitor] [EnvInject] - Injecting as environment variables the properties content 
[Pipeline] [monitor] echo
[monitor] componentsLockDownScript=RegressionComponentsLockDown.py
[Pipeline] [monitor] echo
[monitor] modifyProcessMapXmlScript=ModifyXmlDom-1.20.py
[Pipeline] [monitor] echo
[monitor] uutAndNodePropertiesFile=DL380G8PR2-NodeData-(203).properties
[Pipeline] [monitor] echo
[monitor] 
[Pipeline] [monitor] echo
[monitor] [EnvInject] - Variables injected successfully.

管道插件或Groovy或Jenkins中是否有选项,配置,命令或任何内容,以允许我抑制所有额外的“回显”以使控制台输出更具可读性?

3 个答案:

答案 0 :(得分:1)

你真正想要的是JENKINS-26124。显然你有一些解决方法,但它的实现存在缺陷,我们在这个问题中看不到。

答案 1 :(得分:0)

你需要通过詹金斯来做吗?如果没有,你可以直接从控制台中删除它(假设你在linux控制台上获得输出):

cat YOUR_EXAMPLE_OUTPUT.txt | grep -v '\[Pipeline\]\|\[monitor\]\|^$' 

只会遗漏:

Started by user john.doe@cdf.com
Running on swqa-pr-prod-slave-1 in /srv/jenkins-slave/workspace/UUT Automated Regression - 1.20

/////////////////////////////////////////////////
                Start Execution                  
/////////////////////////////////////////////////

更新: 如果你想要它“实时”,请按照你的输出并将其输入一行缓冲grep:

tail -f YOUR_EXAMPLE_OUTPUT.txt | grep -v '\[Pipeline\]\|\[monitor\]\|^$' --line-buffered

答案 2 :(得分:0)

专门针对您的示例的部分解决方法

/////////////////////////////////////////////////
                Start Execution                  
/////////////////////////////////////////////////

您要实现的功能是在多行上使用单个echo调用

'''triple single quoted string''' (也可以包括插值字符串)。

  

http://docs.groovy-lang.org/latest/html/documentation/#_triple_single_quoted_string

     

三重单引号字符串是多行。您可以跨行边界跨越字符串的内容,而无需将字符串拆分为几段,而不会造成污染或换行符: