I'm currently working on creating log file for Jenkins build using Python script and Jenkins API.
The following function create text file of build's console output and save it into network location. I'm looking into getting file network path so that it can be included in the customised email notifications.
Just wondering if you could help me to get expected result. Thank you.
Code:
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
Expected Result:
[['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']]
Actual Result:
[['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']]