Jenkins Pipeline从ansiColor插件记录大括号?

时间:2018-09-22 13:05:10

标签: jenkins jenkins-plugins jenkins-pipeline

当我使用ansiColor插件输出消息时,我不喜欢它,它会打印很多额外的花括号和单词。如何解决?

Jenkins管道方法:

def printVariable(String message) {
ansiColor('xterm') {
    echo "\033[34m ${message} \033[0m"
}
}

致电:

printVariable("ENVIRONMENT: ${ENVIRONMENT}")
printVariable("PROJECT_VERSION: ${PROJECT_VERSION}")
printVariable("TAG_NAME: ${TAG_NAME}")

输出:

[Pipeline] }
[Pipeline] // ansiColor
[Pipeline] ansiColor
[Pipeline] {
[Pipeline] echo
 ENVIRONMENT: prod 
[Pipeline] }
[Pipeline] // ansiColor
[Pipeline] ansiColor
[Pipeline] {
[Pipeline] echo
 PROJECT_VERSION: 1.0.0 
[Pipeline] }
[Pipeline] // ansiColor
[Pipeline] ansiColor
[Pipeline] {
[Pipeline] echo
 TAG_NAME: repo.bla.bla
[Pipeline] }
[Pipeline] // ansiColor
[Pipeline] ansiColor
[Pipeline] {
[Pipeline] echo

我希望它像这样。

ENVIRONMENT: prod
PROJECT_VERSION: 1.0.0 
TAG_NAME: repo.bla.bla

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

我们使用Simple Theme plugin隐藏或隐藏管道注释的行。这样,您可以使用自定义.css代码隐藏或不显示管道注释的行。如果您已经通过“ Jenkins>管理Jenkins>配置系统”安装了此插件,然后导航到“主题”并添加了额外的CSS,则可以执行此操作。

例如,这不应显示管道注释行:

.pipeline-annotated {
   display: none;
}

或只是将其隐藏(有时会更易读):

.pipeline-annotated {
   visibility: hidden;
}

有关更多信息,另请参见this