Add download artifact role

This role can be used to download a previously built artifact.
Requires a Zuul API endpoint.

Change-Id: I5dd88f67bfa383f5f2bc0cfcc3b2346def796ae7
This commit is contained in:
James E. Blair 2019-03-21 14:57:07 -07:00
parent 189c2471ec
commit fc62f6f36b
3 changed files with 41 additions and 0 deletions

View File

@ -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.

View File

@ -0,0 +1,2 @@
---
download_artifact_query: "change={{ zuul.change }}&patchset={{ zuul.patchset }}&pipeline={{ download_artifact_pipeline }}&job_name={{ download_artifact_job }}"

View File

@ -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 }}"