【发布时间】:2020-08-22 04:26:00
【问题描述】:
抱歉,由于工作中的安全限制,我无法发布实际代码,但我会尝试做一个人为的例子。
我正在使用 python 3.6.1 并在 Azure Pipeline (ADS 2019) 中运行一个模块。在模块中,我们使用具有以下结构的字典完成输出
#dummy data, assume files could be in any order in any category
{
"compliant": ['file1.py', 'file2.py'], #list of files which pass
"non-compliant":['file3.py'], #list of files which fail
"incompatible":['file4.py'] #list of files which could not be tested due to exceptions
}
当发生故障时,我们的一位客户希望脚本输出命令以调用可以运行的脚本来纠正不合规的文件。该程序的编写类似于以下内容
result = some_func() #returns the above dict
print('compliant:')
for file in result['compliant']:
print(file)
print('non-compliant:')
for file in result['non-compliant']:
print(file)
print('incompatible:')
for file in result['incompatible']:
print(file)
# prints a string to sys.stderr simillar to python -m script arg1 arg2 ...
# script that is output is based on the arguments used to call
print_command_to_fix(sys.argv)
正常运行时,我会得到如下正确的输出:
#correct output: occurs on bash and cmd
compliant:
file1.py
file2.py
non-compliant:
file3.py
incompatible:
file4.py
python -m script arg1 arg2 arg_to_fix
当我在 Azure Pipeline 上运行时,输出会像下面这样交错
#incorrect output: occurs only on azure pipeline runs
compliant:
python -m script arg1 arg2 arg_to_fix
file1.py
file2.py
non-compliant:
file3.py
incompatible:
file4.py
无论我尝试使用 print 还是 sys.stderr.write 似乎都无法解决交错问题,并且我假设 print_command_to_fix() 以某种方式被异步调用。但我的猜测可能并不准确,因为我已经很久没有使用 ADS 或 python了。
TL;DR:我做错了什么只在管道上获得上述交错输出?
编辑:澄清某些点并修正错别字
【问题讨论】:
-
你是如何配置你的构建定义的?您是否使用了最新的构建代理?请尝试在您的构建代理机器上手动运行代码以检查结果。此外,在构建管道中将 system.debug 设置为 True 并共享整个日志。
标签: python python-3.x azure output azure-devops-server-2019