From 87b391c84af6601a9bc92cf7cae7323fa3f33aa9 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 23 Jul 2019 15:16:35 -0700 Subject: [PATCH] Download-artifact: use the artifact type rather than name So that the artifact "name" may be used for human consumption, switch the download-artifact role to use the metadata.type attribute of the artifact. This deprecates the download_artifact_name role variable and adds _type as a replacement. Change-Id: I1c4a4be7d1599b233b56fe73117ff097b8ad381a --- roles/download-artifact/README.rst | 8 ++++++++ roles/download-artifact/tasks/main.yaml | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/roles/download-artifact/README.rst b/roles/download-artifact/README.rst index 53bb197b4..a87098029 100644 --- a/roles/download-artifact/README.rst +++ b/roles/download-artifact/README.rst @@ -20,8 +20,16 @@ many artifacts as match the selection criteria. .. zuul:rolevar:: download_artifact_name + .. warning:: This field is deprecated and will be removed. Use + ``download_artifact_type`` instead. + The artifact name. This can be a string or a list of strings. +.. zuul:rolevar:: download_artifact_type + + The artifact type. This is the value of the ``type`` field in the + artifact metadata. 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 }} diff --git a/roles/download-artifact/tasks/main.yaml b/roles/download-artifact/tasks/main.yaml index 0d5d7e6b8..c58a889e7 100644 --- a/roles/download-artifact/tasks/main.yaml +++ b/roles/download-artifact/tasks/main.yaml @@ -5,11 +5,23 @@ - name: Parse build response set_fact: build: "{{ build.json[0] }}" -- name: Download archive +- name: Download archive by name 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)" + when: + - "download_artifact_name is defined" + - "artifact.name == download_artifact_name or ((download_artifact_name | type_debug) == 'list' and artifact.name in download_artifact_name))" +- name: Download archive by type + uri: + url: "{{ artifact.url }}" + dest: "{{ download_artifact_directory }}" + loop: "{{ build.artifacts }}" + loop_control: + loop_var: artifact + when: + - "download_artifact_type is defined" + - "'metadata' in artifact and 'type' in artifact.metadata and (artifact.metadata.type == download_artifact_type or ((download_artifact_type | type_debug) == 'list' and artifact.metadata.type in download_artifact_type))"