首页 > 解决方案 > Jenkins 更新后使用 AnsiColorBuildWrapper 在控制台输出中不再有颜色

问题描述

由于我们已更新到 Jenkins 版本 2.235.1,因此在使用 AnsiColorBuildWrapper 时,控制台输出中的颜色无法正确显示。这使得获得 Ansible 输出的正确概览变得更加困难。

我们的 Jenkins 工作流程中的片段

wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
                println(("\033[31m  ************************** ${role} wird ausgerollt *************************** \033[0m"))
         }
         configFileProvider([configFile(fileId: '1609a7e4-2674-4cef-9945-db9492f2dcd6', variable: 'vaultPassWord')]) {
             wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {               
                 ansiblePlaybook colorized: true, credentialsId: 'app-serveraccess-user',
                 extras: "--extra-vars='env=${currentStage}' --extra-vars='workspace=${workspace}' --extra-vars='app=${app}' -l ${hostname.toLowerCase()} --vault-password-file ${env.vaultPassWord} ${debug_ansible}", installation: 'Ansible',
                 inventory: '/vol1/ansible/hosts', playbook: "/etc/ansible/playbooks/${role}/${role}_config.yml",
                 sude: true, sudoUser: null                          
             }//wrap 
         }//configFileProvider 

控制台输出中的结果:

[159] $ sshpass ******** /usr/bin/ansible-playbook /etc/ansible/playbooks/app/app_config.yml -i /vol1/ansible/hosts -u devadmin -k --extra-vars=env=oat --extra-vars=workspace=/vol1/jenkins/jobs/SERVER-CONFIG-WF/pipeline/159 --extra-vars=app=app -l server-app-r0001.com --vault-password-file /vol1/jenkins/jobs/SERVER-CONFIG-WF/pipeline/159@tmp/config1179695197260634236tmp --diff
17:02:25  [0;35m[DEPRECATION WARNING]: DEFAULT_SUDO_EXE option, In favor of become which is a [0m
17:02:25  [0;35mgeneric framework . This feature will be removed in version 2.8. Deprecation [0m
17:02:25  [0;35mwarnings can be disabled by setting deprecation_warnings=False in ansible.cfg.[0m
17:02:25  [0;35m[DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of become which is a [0m
17:02:25  [0;35mgeneric framework . This feature will be removed in version 2.8. Deprecation [0m
17:02:25  [0;35mwarnings can be disabled by setting deprecation_warnings=False in ansible.cfg.[0m
17:02:25  [1;35m [WARNING]: Found both group and host with same name: localhost[0m

你现在看到的不是颜色,而是 python 用来在控制台上创建它们的控制字符串

所有插件都是最新的

我们能做些什么来解决这个问题?

标签: jenkinsjenkins-pipeline

解决方案


推荐阅读