python - Gitlab CI 在 Python 脚本输出中换行

我想使用 python 脚本在 Gitlab CI 日志中显示一个表。我在本地检查脚本并正确显示表格,但是当我在 gitlab CI 中运行脚本时,它会中断该行,尽管如果您尝试回显任何长行,它会正确输出。

在gitlab ci中需要做些什么才能不破坏python脚本输出表的行?

如果重要的话,我会使用制表库制作表格。

Python 脚本:

#!/usr/bin/env python3

import ruamel.yaml
from tabulate import tabulate
from rich.console import Console

def main():
    with open('cluster.yml', 'r') as cluster_yml:
        cluster_yml_data = yaml.load(cluster_yml)
    path_to_env_file = cluster_yml_data['include'][0]
    with open(path_to_env_file, 'r') as env_yaml:
        env_yaml_data = yaml.load(env_yaml)
    for var, value in env_yaml_data['variables'].items():
        env_yaml_data['variables'][var] = str(env_yaml_data['variables'][var]).replace(' ', '\n')
    console.print(tabulate(env_yaml_data['variables'].items(), tablefmt='fancy_grid', headers=['Variable', 'Value']))

if __name__ == '__main__':
    yaml = ruamel.yaml.YAML()
    yaml.indent(mapping=2, sequence=4, offset=2)
    yaml.preserve_quotes = True
    console = Console(force_terminal=True)
    main()

cluster.yml 文件:

include:
  - 'cluster-init_variables.yml'

cluster-init_variables.yml 文件:

variables:
  FOLDER_PREFIX: "bcs"
  FOLDER_NAME: "sandbox"
  FOLDER: "$FOLDER_PREFIX-$FOLDER_NAME"
  INFRA_REPO: "git@github.com:aaaaaaa/bbbb-bbbbbbb/cccccc/dddddd/$FOLDER-repo.git"
  SUBNET_ZONE_A: "1.1.1.1/24"
  SUBNET_ZONE_B: "2.2.2.2/24"
  SUBNET_ZONE_C: "3.3.3.3/24"
  GROUP_ID: "12"
  CLUSTER_NAME: "cluster"
  NG_WORKER_MEMORY: 24
  NG_WORKER_CORES: 8
  NG_SCALE_MIN: 1
  NG_SCALE_MAX: 3
  NG_SCALE_INITIAL: 1
  NG_WORKER_DISK_SIZE: 64

最佳答案

您可以将 width 参数传递给控制台调用并明确设置宽度。

width (int, optional) – The width of the terminal. Leave as default to auto-detect width.

https://stackoverflow.com/questions/72451350/

相关文章:

c# - 如何转义和忽略 __debugbreak

javascript - React-TypeScript : Expected 0 argumen

javascript - 使用 react-chartjs-2 创建对折线图的引用

ruby-on-rails - Ruby on rails query 不知道怎么写

java - 如何使用二维指针通过 JNA 调用 C 函数?

javascript - javascript(ASP.Net)中的计时器倒计时

python - 直接查询 Sqlalchemy-utils EncrytedType 作为 SQL

ios - 如何在 App Store Connect 中启用 "Access to Cloud M

java - Vertx 运行多个事件循环

javascript - 我如何构建一个用一组新按钮回复的不和谐按钮