Add link to artifacts for upgrade jobs
Change-Id: If72ef37d84103fccea90255fd0989413acc9278f
Related-prod: PROD-30994
diff --git a/daily_jenkins_job_report/daily_report/config.py b/daily_jenkins_job_report/daily_report/config.py
index 6d4e825..3407c0b 100755
--- a/daily_jenkins_job_report/daily_report/config.py
+++ b/daily_jenkins_job_report/daily_report/config.py
@@ -38,6 +38,9 @@
'oscore-test-openstack-upgrade-pike-queens-core-barbican',
]
+# For getting artifacts link for the single jobs
+LOGS_DIRECTORY = '/var/www/oscore_jobs.com/html/oscore_logs/'
+
# Logging
LOGGER = 'generate_report'
LOG_FOLDER = '/tmp/'
diff --git a/daily_jenkins_job_report/daily_report/generate_report.py b/daily_jenkins_job_report/daily_report/generate_report.py
index aa6a8ff..d8f187b 100755
--- a/daily_jenkins_job_report/daily_report/generate_report.py
+++ b/daily_jenkins_job_report/daily_report/generate_report.py
@@ -19,12 +19,14 @@
import config
import datetime
+import jinja2
import logging
import re
import update_google_sheets
-import jinja2
+from get_artifacts_links_single_jobs import update_all_jobs_results_with_artifacts
+
from jinja2 import Template
from jenkinsapi import custom_exceptions
from jenkinsapi.jenkins import Jenkins
@@ -206,5 +208,8 @@
all_jobs_results = get_all_jobs_results()
logger.info(f'all_jobs_results: {all_jobs_results}')
+ all_jobs_results = update_all_jobs_results_with_artifacts(all_jobs_results)
+
save_results_to_html(all_jobs_results)
update_google_sheets.update_google_sheet(all_jobs_results)
+
diff --git a/daily_jenkins_job_report/daily_report/get_artifacts_links_single_jobs.py b/daily_jenkins_job_report/daily_report/get_artifacts_links_single_jobs.py
new file mode 100644
index 0000000..70e79da
--- /dev/null
+++ b/daily_jenkins_job_report/daily_report/get_artifacts_links_single_jobs.py
@@ -0,0 +1,59 @@
+from pathlib import Path
+
+import config
+import os
+import re
+
+
+def get_full_filename(job_name, job_id):
+ if not job_name or not job_id:
+ return
+ full_patch = config.LOGS_DIRECTORY + job_name + '/'
+ patch_obj = Path(full_patch)
+ if not patch_obj.exists():
+ return
+
+ file_obj = list(patch_obj.glob(f'{job_id}*.txt'))
+ if len(file_obj) == 0:
+ return
+ return file_obj[0].as_posix()
+
+
+def get_artifact_filename_id(file_patch):
+ if not file_patch:
+ return
+
+ with open(file_patch) as file:
+ for file_line in file:
+ if "Starting building: oscore-artifatcts-collector" in file_line:
+ artifact_id = file_line.split('#')[-1]
+ return artifact_id.rstrip()
+
+
+def get_artifact_link(artifact_file_patch):
+ if not artifact_file_patch:
+ return
+
+ with open(artifact_file_patch) as file:
+ for file_line in file:
+ if """https://artifactory.mcp.mirantis.net/""" in file_line:
+ artifact_link = re.findall('https:\/\/artifactory\.mcp\.mirantis\.net\/artifactory\/oscore-local\/[a-zA-Z0-9-.]*\/[0-9-_]*\/', file_line)
+ return artifact_link[0]
+
+
+def update_all_jobs_results_with_artifacts(all_jobs_results):
+ single_jobs_results = all_jobs_results['single_results']
+ for job in single_jobs_results:
+ job_id = all_jobs_results['single_results'][job]['baseurl'].split('/')[-1]
+ job_name = all_jobs_results['single_results'][job]['job_name']
+
+ file_patch = get_full_filename(job_name, job_id)
+
+ artifact_filename_id = get_artifact_filename_id(file_patch)
+ artifact_file_patch = get_full_filename(job_name='oscore-artifatcts-collector', job_id=artifact_filename_id)
+ artifact_link = get_artifact_link(artifact_file_patch)
+
+ all_jobs_results['single_results'][job]['artifacts'] = artifact_link
+
+ return all_jobs_results
+
diff --git a/daily_jenkins_job_report/daily_report/templates/report_template.html b/daily_jenkins_job_report/daily_report/templates/report_template.html
index f96a3be..a928184 100755
--- a/daily_jenkins_job_report/daily_report/templates/report_template.html
+++ b/daily_jenkins_job_report/daily_report/templates/report_template.html
@@ -76,6 +76,7 @@
<th>Build status</th>
<th>Job name</th>
<th>Base URL</th>
+ <th>Artifacts</th>
</tr>
{% for key, value in results['single_results'].items() %}
@@ -91,6 +92,7 @@
<td>{{ value.build_status }}</td>
<td>{{ value.job_name }}</td>
<td><a href="{{ value.baseurl }}">{{ value.baseurl[32:] }}</a></td>
+ <td><a href="{{ value.artifacts }}">link</a></td>
</tr>
{% endfor %}
</table>