Gitlab CI 在 Python 脚本输出中换行
Gitlab CI breaks line in Python script output
我想使用 python 脚本在 Gitlab CI 日志中显示一个 table。我在本地检查脚本并正确显示 table,但是当我 运行 gitlab CI 中的脚本时,它会中断该行,尽管如果您尝试回显任何长行,它会正确输出。
gitlab ci 需要做些什么才能不破坏 python 脚本输出的行 table?
如果它很重要,我会使用制表库制作一个 table。
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'
集群-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.
我想使用 python 脚本在 Gitlab CI 日志中显示一个 table。我在本地检查脚本并正确显示 table,但是当我 运行 gitlab CI 中的脚本时,它会中断该行,尽管如果您尝试回显任何长行,它会正确输出。
gitlab ci 需要做些什么才能不破坏 python 脚本输出的行 table?
如果它很重要,我会使用制表库制作一个 table。
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'
集群-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.