我目前正在使用 Python 脚本和 Jenkins API 为 Jenkins 构建创建日志文件。
以下函数创建构建控制台输出的文本文件并将其保存到网络位置。我正在研究获取文件网络路径,以便它可以包含在自定义的电子邮件通知中。
只是想知道您是否可以帮助我获得预期的结果。谢谢你。
代码:
job_list = ['project_name1', 'project_name2', 'project_name3']
def create_log_file(job_list):
log_file_info = []
for job in job_list:
file_name = os.path.join('//network_location/folder/subfolder1/subfolder2/subfolder3/Jenkins_Build/buildlog/windows/', job + "_" + current_date + file_format)
file_content = get_console_output(job)
with open(file_name, 'w', encoding="utf-8") as f:
f.write(file_content)
log_file = ['{}: {}'.format(job, file_name.replace("/", "\\"))]
log_file_info.append(log_file)
return log_file_info
预期结果:
[['project_name1: \network_location\folder\subfolder1\subfolder2\subfolder3\Jenkins_Build\buildlog\windows\project_name1_2018-10-24.txt'],['project_name2: \network_location\folder\subfolder1\subfolder2\subfolder3\Jenkins_Build\buildlog \windows\project_name2_2018-10-24.txt'], ['project_name3: \network_location\folder\subfolder1\subfolder2\subfolder3\Jenkins_Build\buildlog\windows\project_name3_2018-10-24.txt']]
实际结果:
[['project_name1: \\\\network_location\\folder\\subfolder1\\subfolder2\\subfolder3\\Jenkins_Build\\buildlog\\windows\\project_name1_2018-10-24.txt'], ['project_name2: \\\ \network_location\\folder\\subfolder1\\subfolder2\\subfolder3\\Jenkins_Build\\buildlog\\windows\\project_name2_2018-10-24.txt'],
['project_name3: \\network_location\\folder\\subfolder1 \\subfolder2\\subfolder3\\Jenkins_Build\\buildlog\\windows\\project_name3_2018-10-24.txt']]