Search code examples
pythongitlabtabulate

Gitlab CI breaks line in Python script output


I want to display a table in Gitlab CI log using python script. I check the script locally and it displays the table correctly, but when I run the script in gitlab CI, it breaks the line, although if you try to echo any long line, it will output it correctly.

What needs to be done in gitlab ci so that it does not break the line of the python script output table?

I make a table using the tabulate library, if it's important.

enter image description here

Python script:

#!/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 file:

include:
  - 'cluster-init_variables.yml'

cluster-init_variables.yml file:

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

Solution

  • You could pass width argument to Console call and set the width explicitly.

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