jenkins 彩色日志显示

jenkins 彩色日志显示

示例:这里用到ansiColor插件,在Jenkins输出有颜色的日志信息
image

流水线语法的生成

image

ansiColor('xterm') {
    // some block
}

tools.groovy

package org.devops

//格式化输出
def PrintMes(value,color){
    colors = ['red'    : "\033[40;31m >>>>>>>>>>${value}<<<<<<<<<< \033[0m",
              'red1'   : "\033[40;41m >>>>>>>>>>${value}<<<<<<<<<< \033[0m",
              'green'  : "\033[40;32m >>>>>>>>>>${value}<<<<<<<<<< \033[0m",
              'green1' : "\033[40;42m >>>>>>>>>>${value}<<<<<<<<<< \033[0m",
              'yellow' : "\033[40;33m >>>>>>>>>>${value}<<<<<<<<<< \033[0m",
              'yellow1': "\033[40;43m >>>>>>>>>>${value}<<<<<<<<<< \033[0m",
              'blue'   : "\033[47;34m >>>>>>>>>>${value}<<<<<<<<<< \033[0m",
              'blue1'  : "\033[47;44m >>>>>>>>>>${value}<<<<<<<<<< \033[0m"
             ]
    ansiColor('xterm') {
        println(colors[color])
    }
}

Jenkinsfile

@Library('jenkinslib') _     
def tools = new org.devops.tools()
pipeline {
 
	agent any
	stages {
		stage("hello"){
			steps{
				script{
					tools.Post("success",'green')
				}
			}
		}
	}
}

image

转自

https://blog.csdn.net/weixin_44802620/article/details/125133847

posted @ 2023-03-30 21:20  liwenchao1995  阅读(178)  评论(0编辑  收藏  举报