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:
James E. Blair 2019-01-02 15:23:14 -08:00
parent 7d3ad9a7aa
commit b7c68c2f76
4 changed files with 34 additions and 4 deletions

View File

@ -755,7 +755,10 @@ under the **zuul.artifacts** dictionary. For example:
- name: tarball
url: http://example.com/path/to/package.tar.gz
- name: docs
url: http://example.com/path/to/docs
url: build/docs/
If the value of **url** is a relative URL, it will be combined with
the **zuul.log_url** value if set to create an absolute URL.
Skipping child jobs
~~~~~~~~~~~~~~~~~~~

View File

@ -4,8 +4,12 @@
zuul_return:
data:
zuul:
log_url: http://logs.example.com/build
foo: bar
artifacts:
- name: tarball
url: http://example.com/tarball
- name: docs
url: http://example.com/docs
- name: relative
url: relative/docs

View File

@ -701,10 +701,12 @@ class TestArtifacts(ZuulDBTestCase, BaseTestWeb, AnsibleZuulTestCase):
"project=org/project&"
"job_name=project-test1").json()
self.assertEqual(len(build_query), 1)
self.assertEqual(len(build_query[0]['artifacts']), 2)
self.assertEqual(len(build_query[0]['artifacts']), 3)
self.assertEqual(build_query[0]['artifacts'], [
{'url': 'http://example.com/tarball',
'name': 'tarball'},
{'url': 'http://example.com/docs',
'name': 'docs'},
{'url': 'http://logs.example.com/build/relative/docs',
'name': 'relative'},
])

View File

@ -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():