From b7c68c2f76a6d3bf90718407ba16cc06c91708e8 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 2 Jan 2019 15:23:14 -0800 Subject: 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 --- doc/source/user/jobs.rst | 5 ++++- .../git/common-config/playbooks/project-test1.yaml | 4 ++++ tests/unit/test_web.py | 4 +++- zuul/driver/sql/sqlreporter.py | 25 ++++++++++++++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/doc/source/user/jobs.rst b/doc/source/user/jobs.rst index af947dd33..1af0bce6a 100644 --- a/doc/source/user/jobs.rst +++ b/doc/source/user/jobs.rst @@ -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 ~~~~~~~~~~~~~~~~~~~ diff --git a/tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml b/tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml index 7f2d48e11..2dce5367e 100644 --- a/tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml +++ b/tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml @@ -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 diff --git a/tests/unit/test_web.py b/tests/unit/test_web.py index 716f2f91f..632a0a2c6 100755 --- a/tests/unit/test_web.py +++ b/tests/unit/test_web.py @@ -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'}, ]) diff --git a/zuul/driver/sql/sqlreporter.py b/zuul/driver/sql/sqlreporter.py index 2a7ae8570..f545da00d 100644 --- a/zuul/driver/sql/sqlreporter.py +++ b/zuul/driver/sql/sqlreporter.py @@ -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(): -- cgit v1.2.1