Skip to content

Commit 4e1dd27

Browse files
authored
Merge pull request #767 from python-gitlab/fix/744/delete_artifacts
feature: Implement artifacts deletion
2 parents e45a6e2 + 76b6e1f commit 4e1dd27

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

docs/gl_objects/builds.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ Mark a job artifact as kept when expiration is set::
319319

320320
build_or_job.keep_artifacts()
321321

322+
Delete the artifacts of a job::
323+
324+
build_or_job.delete_artifacts()
325+
322326
Get a job trace::
323327

324328
build_or_job.trace()

gitlab/v4/objects.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,21 @@ def keep_artifacts(self, **kwargs):
15841584
path = "%s/%s/artifacts/keep" % (self.manager.path, self.get_id())
15851585
self.manager.gitlab.http_post(path)
15861586

1587+
@cli.register_custom_action("ProjectJob")
1588+
@exc.on_http_error(exc.GitlabCreateError)
1589+
def delete_artifacts(self, **kwargs):
1590+
"""Delete artifacts of a job.
1591+
1592+
Args:
1593+
**kwargs: Extra options to send to the server (e.g. sudo)
1594+
1595+
Raises:
1596+
GitlabAuthenticationError: If authentication is not correct
1597+
GitlabDeleteError: If the request could not be performed
1598+
"""
1599+
path = "%s/%s/artifacts" % (self.manager.path, self.get_id())
1600+
self.manager.gitlab.http_delete(path)
1601+
15871602
@cli.register_custom_action("ProjectJob")
15881603
@exc.on_http_error(exc.GitlabGetError)
15891604
def artifacts(self, streamed=False, action=None, chunk_size=1024, **kwargs):

tools/python_test_v4.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@
421421

422422
# commit status
423423
commit = admin_project.commits.list()[0]
424+
size = len(commit.statuses.list())
424425
status = commit.statuses.create({"state": "success", "sha": commit.id})
425-
assert len(commit.statuses.list()) == 1
426+
assert len(commit.statuses.list()) == size + 1
426427

427428
assert commit.refs()
428429
assert commit.merge_requests() is not None

0 commit comments

Comments
 (0)