Skip to content

Commit

Permalink
Support downloading a single artifact file
Browse files Browse the repository at this point in the history
Fixes #432
  • Loading branch information
Gauvain Pocentek committed Mar 17, 2018
1 parent 9cb6bbe commit 9080f69
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docs/gl_objects/builds.rst
Expand Up @@ -297,7 +297,7 @@ Get a job:
:start-after: # get job
:end-before: # end get job

Get a job artifact:
Get the artifacts of a job:

.. literalinclude:: builds.py
:start-after: # artifacts
Expand All @@ -316,12 +316,17 @@ stream:
:start-after: # stream artifacts with class
:end-before: # end stream artifacts with class

In this second example, you can directly stream the output into a file, and unzip it afterwards:
In this second example, you can directly stream the output into a file, and
unzip it afterwards:

.. literalinclude:: builds.py
:start-after: # stream artifacts with unzip
:end-before: # end stream artifacts with unzip

Get a single artifact file::

build_or_job.artifact('path/to/file')

Mark a job artifact as kept when expiration is set:

.. literalinclude:: builds.py
Expand Down
28 changes: 28 additions & 0 deletions gitlab/v4/objects.py
Expand Up @@ -1012,6 +1012,34 @@ def artifacts(self, streamed=False, action=None, chunk_size=1024,
**kwargs)
return utils.response_content(result, streamed, action, chunk_size)

@cli.register_custom_action('ProjectJob')
@exc.on_http_error(exc.GitlabGetError)
def artifact(self, path, streamed=False, action=None, chunk_size=1024,
**kwargs):
"""Get a single artifact file from within the job's artifacts archive.
Args:
path (str): Path of the artifact
streamed (bool): If True the data will be processed by chunks of
`chunk_size` and each chunk is passed to `action` for
treatment
action (callable): Callable responsible of dealing with chunk of
data
chunk_size (int): Size of each chunk
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the artifacts could not be retrieved
Returns:
str: The artifacts if `streamed` is False, None otherwise.
"""
path = '%s/%s/artifacts/%s' % (self.manager.path, self.get_id(), path)
result = self.manager.gitlab.http_get(path, streamed=streamed,
**kwargs)
return utils.response_content(result, streamed, action, chunk_size)

@cli.register_custom_action('ProjectJob')
@exc.on_http_error(exc.GitlabGetError)
def trace(self, streamed=False, action=None, chunk_size=1024, **kwargs):
Expand Down

0 comments on commit 9080f69

Please sign in to comment.