Merge "Combine artifact URLs with log_url if relative"
This commit is contained in:
commit
2a2dbc51dc
|
@ -755,7 +755,10 @@ under the **zuul.artifacts** dictionary. For example:
|
||||||
- name: tarball
|
- name: tarball
|
||||||
url: http://example.com/path/to/package.tar.gz
|
url: http://example.com/path/to/package.tar.gz
|
||||||
- name: docs
|
- 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
|
Skipping child jobs
|
||||||
~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -4,8 +4,12 @@
|
||||||
zuul_return:
|
zuul_return:
|
||||||
data:
|
data:
|
||||||
zuul:
|
zuul:
|
||||||
|
log_url: http://logs.example.com/build
|
||||||
|
foo: bar
|
||||||
artifacts:
|
artifacts:
|
||||||
- name: tarball
|
- name: tarball
|
||||||
url: http://example.com/tarball
|
url: http://example.com/tarball
|
||||||
- name: docs
|
- name: docs
|
||||||
url: http://example.com/docs
|
url: http://example.com/docs
|
||||||
|
- name: relative
|
||||||
|
url: relative/docs
|
||||||
|
|
|
@ -701,10 +701,12 @@ class TestArtifacts(ZuulDBTestCase, BaseTestWeb, AnsibleZuulTestCase):
|
||||||
"project=org/project&"
|
"project=org/project&"
|
||||||
"job_name=project-test1").json()
|
"job_name=project-test1").json()
|
||||||
self.assertEqual(len(build_query), 1)
|
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'], [
|
self.assertEqual(build_query[0]['artifacts'], [
|
||||||
{'url': 'http://example.com/tarball',
|
{'url': 'http://example.com/tarball',
|
||||||
'name': 'tarball'},
|
'name': 'tarball'},
|
||||||
{'url': 'http://example.com/docs',
|
{'url': 'http://example.com/docs',
|
||||||
'name': 'docs'},
|
'name': 'docs'},
|
||||||
|
{'url': 'http://logs.example.com/build/relative/docs',
|
||||||
|
'name': 'relative'},
|
||||||
])
|
])
|
||||||
|
|
|
@ -16,6 +16,7 @@ import datetime
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import voluptuous as v
|
import voluptuous as v
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
from zuul.reporter import BaseReporter
|
from zuul.reporter import BaseReporter
|
||||||
|
|
||||||
|
@ -32,7 +33,9 @@ class SQLReporter(BaseReporter):
|
||||||
}
|
}
|
||||||
zuul_data = {
|
zuul_data = {
|
||||||
'zuul': {
|
'zuul': {
|
||||||
'artifacts': [artifact]
|
'log_url': str,
|
||||||
|
'artifacts': [artifact],
|
||||||
|
v.Extra: object,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
artifact_schema = v.Schema(zuul_data)
|
artifact_schema = v.Schema(zuul_data)
|
||||||
|
@ -103,11 +106,29 @@ class SQLReporter(BaseReporter):
|
||||||
if self.validateArtifactSchema(build.result_data):
|
if self.validateArtifactSchema(build.result_data):
|
||||||
artifacts = build.result_data.get('zuul', {}).get(
|
artifacts = build.result_data.get('zuul', {}).get(
|
||||||
'artifacts', [])
|
'artifacts', [])
|
||||||
|
default_url = build.result_data.get('zuul', {}).get(
|
||||||
|
'log_url')
|
||||||
|
if default_url:
|
||||||
|
if default_url[-1] != '/':
|
||||||
|
default_url += '/'
|
||||||
for artifact in artifacts:
|
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(
|
db_build.createArtifact(
|
||||||
name=artifact['name'],
|
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():
|
def getSchema():
|
||||||
|
|
Loading…
Reference in New Issue