Skip to content

teamcity

env_vars()

Read basic environment variables from Teamcity.

Returns:

Type Description
OneOf[Issue, EnvVars]

An EnvVar instance.

Source code in m/log/ci_tools/providers/teamcity.py
def env_vars() -> OneOf[Issue, EnvVars]:
    """Read basic environment variables from Teamcity.

    Returns:
        An EnvVar instance.
    """
    # WIP: Need to map other variables here. Not willing to do
    # at the moment since I'm using Github.
    return Good(EnvVars(ci_env=True))

escape_msg(msg)

Escapes characters so Teamcity can print correctly.

https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-Escapedvalues

Parameters:

Name Type Description Default
msg str

The message to process.

required

Returns:

Type Description
str

A message that can be provided to Teamcity.

Source code in m/log/ci_tools/providers/teamcity.py
def escape_msg(msg: str) -> str:
    """Escapes characters so Teamcity can print correctly.

    https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-Escapedvalues

    Args:
        msg: The message to process.

    Returns:
        A message that can be provided to Teamcity.
    """
    message = msg
    for target, replacement in REPLACEMENTS:
        message = message.replace(target, replacement)
    return message

log_format(_formatter, record, show_traceback, debug_python)

Format a log record using the functions provided in this module.

This function is meant to be used by a log formatter. See more info

See:: https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-BlocksofServiceMessages

Parameters:

Name Type Description Default
_formatter Formatter

A log formatter instance.

required
record LogRecord

A log record.

required
show_traceback bool

If true, display the python stack trace.

required
debug_python bool

If true, display the location of the record's origin.

required

Returns:

Type Description
str

A formatted string.

Source code in m/log/ci_tools/providers/teamcity.py
def log_format(
    _formatter: logging.Formatter,
    record: logging.LogRecord,
    show_traceback: bool,
    debug_python: bool,
) -> str:
    """Format a log record using the functions provided in this module.

    This function is meant to be used by a log formatter. See more info

    See::
        https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-BlocksofServiceMessages

    Args:
        _formatter: A log formatter instance.
        record: A log record.
        show_traceback: If true, display the python stack trace.
        debug_python: If true, display the location of the record's origin.

    Returns:
        A formatted string.
    """
    record_dict = record.__dict__

    open_b = _fmt_open(record_dict)
    if open_b:
        return open_b

    close_b = record_dict.get('close_block')
    if close_b:
        return _tc('blockClosed', postfix='', name=close_b)

    indent_padding = 2 if record.levelname in {'WARNING', 'ERROR'} else 3
    indent = len(record.levelname) + indent_padding

    context = format_context(record, indent, show_traceback=show_traceback)
    if not record.msg:
        return context[1:]

    ci_info = record_dict.get('ci_info', Message(msg=record.msg))
    msg_info = format_location([ci_info.file, ci_info.line, ci_info.col])
    msg_info = f'{msg_info}:' if msg_info else ''

    loc = (
        format_location([record.pathname, f'{record.lineno}'])
        if debug_python
        else ''
    )

    msg = f'{loc}{msg_info} {record.msg}'.lstrip()
    if record.levelname == 'WARNING':
        msg = _tc(
            'message',
            status='WARNING',
            text=msg,
            postfix=context,
        )
    elif record.levelname == 'ERROR':
        msg = _tc('buildProblem', postfix=context, description=msg)
    else:
        msg = default_record_fmt(record, '', f'{msg_info}{loc}', context)
    return msg