Combine artifact URLs with log_url if relative
The plan for the idea of a "promote" pipeline is to fetch previously uploaded artifacts from the build log server and move them to the final publication location. However, jobs which store data (such as documentation builds, tarballs, or container images) on the log server should not need to know the configuration of the log server in order to return the artifact URL to zuul. To support this, if the job returns a relative URL for an artifact, assume it is relative to the log URL for the build and combine the two when storing the artifact info. Change-Id: I4bce2401c9e59fd469e3b3da2973514c07faecf2
This commit is contained in:
@@ -16,6 +16,7 @@ import datetime
|
||||
import logging
|
||||
import time
|
||||
import voluptuous as v
|
||||
import urllib.parse
|
||||
|
||||
from zuul.reporter import BaseReporter
|
||||
|
||||
@@ -32,7 +33,9 @@ class SQLReporter(BaseReporter):
|
||||
}
|
||||
zuul_data = {
|
||||
'zuul': {
|
||||
'artifacts': [artifact]
|
||||
'log_url': str,
|
||||
'artifacts': [artifact],
|
||||
v.Extra: object,
|
||||
}
|
||||
}
|
||||
artifact_schema = v.Schema(zuul_data)
|
||||
@@ -103,11 +106,29 @@ class SQLReporter(BaseReporter):
|
||||
if self.validateArtifactSchema(build.result_data):
|
||||
artifacts = build.result_data.get('zuul', {}).get(
|
||||
'artifacts', [])
|
||||
default_url = build.result_data.get('zuul', {}).get(
|
||||
'log_url')
|
||||
if default_url:
|
||||
if default_url[-1] != '/':
|
||||
default_url += '/'
|
||||
for artifact in artifacts:
|
||||
url = artifact['url']
|
||||
if default_url:
|
||||
# If the artifact url is relative, it will
|
||||
# be combined with the log_url; if it is
|
||||
# absolute, it will replace it.
|
||||
try:
|
||||
url = urllib.parse.urljoin(default_url, url)
|
||||
except Exception:
|
||||
self.log.debug("Error parsing URL:",
|
||||
exc_info=1)
|
||||
db_build.createArtifact(
|
||||
name=artifact['name'],
|
||||
url=artifact['url'],
|
||||
url=url,
|
||||
)
|
||||
else:
|
||||
self.log.debug("Result data did not pass artifact schema "
|
||||
"validation: %s", build.result_data)
|
||||
|
||||
|
||||
def getSchema():
|
||||
|
||||
Reference in New Issue
Block a user