Skip to content

Commit b3e0974

Browse files
author
Gauvain Pocentek
committed
Add support for build artifacts and trace
Fixes #122
1 parent 422b163 commit b3e0974

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

gitlab/cli.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
gitlab.ProjectBranch: {'protect': {'required': ['id', 'project-id']},
3737
'unprotect': {'required': ['id', 'project-id']}},
3838
gitlab.ProjectBuild: {'cancel': {'required': ['id', 'project-id']},
39-
'retry': {'required': ['id', 'project-id']}},
39+
'retry': {'required': ['id', 'project-id']},
40+
'artifacts': {'required': ['id', 'project-id']},
41+
'trace': {'required': ['id', 'project-id']}},
4042
gitlab.ProjectCommit: {'diff': {'required': ['id', 'project-id']},
4143
'blob': {'required': ['id', 'project-id',
4244
'filepath']},
@@ -250,6 +252,20 @@ def do_project_build_retry(self, cls, gl, what, args):
250252
except Exception as e:
251253
_die("Impossible to retry project build (%s)" % str(e))
252254

255+
def do_project_build_artifacts(self, cls, gl, what, args):
256+
try:
257+
o = self.do_get(cls, gl, what, args)
258+
return o.artifacts()
259+
except Exception as e:
260+
_die("Impossible to get project build artifacts (%s)" % str(e))
261+
262+
def do_project_build_trace(self, cls, gl, what, args):
263+
try:
264+
o = self.do_get(cls, gl, what, args)
265+
return o.trace()
266+
except Exception as e:
267+
_die("Impossible to get project build trace (%s)" % str(e))
268+
253269
def do_project_issue_subscribe(self, cls, gl, what, args):
254270
try:
255271
o = self.do_get(cls, gl, what, args)

gitlab/objects.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,18 +806,48 @@ class ProjectBuild(GitlabObject):
806806
canUpdate = False
807807
canCreate = False
808808

809-
def cancel(self):
809+
def cancel(self, **kwargs):
810810
"""Cancel the build."""
811811
url = '/projects/%s/builds/%s/cancel' % (self.project_id, self.id)
812812
r = self.gitlab._raw_post(url)
813813
raise_error_from_response(r, GitlabBuildCancelError, 201)
814814

815-
def retry(self):
815+
def retry(self, **kwargs):
816816
"""Retry the build."""
817817
url = '/projects/%s/builds/%s/retry' % (self.project_id, self.id)
818818
r = self.gitlab._raw_post(url)
819819
raise_error_from_response(r, GitlabBuildRetryError, 201)
820820

821+
def artifacts(self, **kwargs):
822+
"""Get the build artifacts.
823+
824+
Returns:
825+
str: The artifacts.
826+
827+
Raises:
828+
GitlabConnectionError: If the server cannot be reached.
829+
GitlabGetError: If the artifacts are not available.
830+
"""
831+
url = '/projects/%s/builds/%s/artifacts' % (self.project_id, self.id)
832+
r = self.gitlab._raw_get(url)
833+
raise_error_from_response(r, GitlabGetError, 200)
834+
return r.content
835+
836+
def trace(self, **kwargs):
837+
"""Get the build trace.
838+
839+
Returns:
840+
str: The trace.
841+
842+
Raises:
843+
GitlabConnectionError: If the server cannot be reached.
844+
GitlabGetError: If the trace is not available.
845+
"""
846+
url = '/projects/%s/builds/%s/trace' % (self.project_id, self.id)
847+
r = self.gitlab._raw_get(url)
848+
raise_error_from_response(r, GitlabGetError, 200)
849+
return r.content
850+
821851

822852
class ProjectBuildManager(BaseManager):
823853
obj_cls = ProjectBuild

0 commit comments

Comments
 (0)