diff --git a/roles/download-artifact/README.rst b/roles/download-artifact/README.rst new file mode 100644 index 000000000..4bb2fa6ed --- /dev/null +++ b/roles/download-artifact/README.rst @@ -0,0 +1,28 @@ +Download an artifact 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. + +**Role Variables** + +.. zuul:rolevar:: download_artifact_api + + The Zuul API endpoint to use. Example: ``https://zuul.example.org/api/tenant/{{ zuul.tenant }}`` + +.. zuul:rolevar:: download_artifact_pipeline + + The pipeline in which the previous build ran. + +.. zuul:rolevar:: download_artifact_job + + The job of the previous build. + +.. zuul:rolevar:: download_artifact_name + + The artifact name. + +.. 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. diff --git a/roles/download-artifact/defaults/main.yaml b/roles/download-artifact/defaults/main.yaml new file mode 100644 index 000000000..abda6f363 --- /dev/null +++ b/roles/download-artifact/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +download_artifact_query: "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 new file mode 100644 index 000000000..fc2e9b886 --- /dev/null +++ b/roles/download-artifact/tasks/main.yaml @@ -0,0 +1,11 @@ +- name: Query Zuul API for artifact information + uri: + url: "{{ download_artifact_api }}/builds?{{ download_artifact_query }}" + register: build +- 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 }}"