From 6523b6a5306b25ce39c33c6069c6125fae8e65c8 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 3 Jun 2019 16:20:34 -0700 Subject: [PATCH] Allow download-artifact to download multiple files In order to support downloading artifacts from a python build job, which mayb produce multiple sdist tarballs and wheels, allow this role to download as many files as match the input parameters. Change-Id: I59de60127b1e8499ae3e48f2a1bc56c7a36b7425 --- roles/download-artifact/README.rst | 17 +++++++++++------ roles/download-artifact/defaults/main.yaml | 1 + roles/download-artifact/tasks/inner.yaml | 8 ++++++++ roles/download-artifact/tasks/main.yaml | 9 +++++---- 4 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 roles/download-artifact/tasks/inner.yaml diff --git a/roles/download-artifact/README.rst b/roles/download-artifact/README.rst index 4bb2fa6ed..53bb197b4 100644 --- a/roles/download-artifact/README.rst +++ b/roles/download-artifact/README.rst @@ -1,7 +1,8 @@ -Download an artifact from a completed build of a Zuul job +Download artifacts from a completed build of a Zuul job -Given a change downloads an artifact from a previous build (by default -of the current change) into the work directory. +Given a change, downloads artifacts from a previous build (by default +of the current change) into the work directory. This will download as +many artifacts as match the selection criteria. **Role Variables** @@ -19,10 +20,14 @@ of the current change) into the work directory. .. zuul:rolevar:: download_artifact_name - The artifact name. + The artifact name. This can be a string or a list of strings. .. zuul:rolevar:: download_artifact_query :default: change={{ zuul.change }}&patchset={{ zuul.patchset }}&pipeline={{ download_artifact_pipeline }}&job_name={{ download_artifact_job }} - The query to use to find the build. This should return exactly one - result. Normally the default is used. + The query to use to find the build. Normally the default is used. + +.. zuul:rolevar:: download_artifact_directory + :default: {{ zuul.executor.work_root }} + + The directory in which to place the downloaded artifacts. diff --git a/roles/download-artifact/defaults/main.yaml b/roles/download-artifact/defaults/main.yaml index abda6f363..56abfcf00 100644 --- a/roles/download-artifact/defaults/main.yaml +++ b/roles/download-artifact/defaults/main.yaml @@ -1,2 +1,3 @@ --- download_artifact_query: "change={{ zuul.change }}&patchset={{ zuul.patchset }}&pipeline={{ download_artifact_pipeline }}&job_name={{ download_artifact_job }}" +download_artifact_directory: "{{ zuul.executor.work_root }}" diff --git a/roles/download-artifact/tasks/inner.yaml b/roles/download-artifact/tasks/inner.yaml new file mode 100644 index 000000000..3db238850 --- /dev/null +++ b/roles/download-artifact/tasks/inner.yaml @@ -0,0 +1,8 @@ +- name: Download archive + uri: + url: "{{ artifact.url }}" + dest: "{{ download_artifact_directory }}" + loop: "{{ (build.artifacts }}" + loop_control: + loop_var: artifact + when: "artifact.name == download_artifact_name or ((download_artifact_name | type_debug) == 'list' and artifact.name in download_artifact_name)" diff --git a/roles/download-artifact/tasks/main.yaml b/roles/download-artifact/tasks/main.yaml index fc2e9b886..5daf4af29 100644 --- a/roles/download-artifact/tasks/main.yaml +++ b/roles/download-artifact/tasks/main.yaml @@ -5,7 +5,8 @@ - name: Extract artifact URL set_fact: archive_url: "{{ (build.json[0].artifacts | selectattr('name', 'equalto', download_artifact_name) | list)[0].url }}" -- name: Download archive - uri: - url: "{{ archive_url }}" - dest: "{{ zuul.executor.work_root }}" +- name: Process build + loop: "{{ build.json }}" + loop_control: + loop_var: build + include_tasks: inner.yaml