Skip to content

Commit 8257400

Browse files
author
Gauvain Pocentek
committed
Add support for project pipelines
1 parent ef2dbf7 commit 8257400

File tree

5 files changed

+110
-2
lines changed

5 files changed

+110
-2
lines changed

docs/gl_objects/projects.py

+20
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,23 @@
382382
# service delete
383383
service.delete()
384384
# end service delete
385+
386+
# pipeline list
387+
pipelines = gl.project_pipelines.list(project_id=1)
388+
# or
389+
pipelines = project.pipelines.list()
390+
# end pipeline list
391+
392+
# pipeline get
393+
pipeline = gl.project_pipelines.get(pipeline_id, project_id=1)
394+
# or
395+
pipeline = project.pipelines.get(pipeline_id)
396+
# end pipeline get
397+
398+
# pipeline retry
399+
pipeline.retry()
400+
# end pipeline retry
401+
402+
# pipeline cancel
403+
pipeline.cancel()
404+
# end pipeline cancel

docs/gl_objects/projects.rst

+31
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,37 @@ Delete a project hook:
395395
:start-after: # hook delete
396396
:end-before: # end hook delete
397397

398+
Pipelines
399+
---------
400+
401+
Use :class:`~gitlab.objects.ProjectPipeline` objects to manipulate projects
402+
pipelines. The :attr:`gitlab.Gitlab.project_pipelines` and
403+
:attr:`Project.services <gitlab.objects.Projects.pipelines>` manager objects
404+
provide helper functions.
405+
406+
List pipelines for a project:
407+
408+
.. literalinclude:: projects.py
409+
:start-after: # pipeline list
410+
:end-before: # end pipeline list
411+
412+
Get a pipeline for a project:
413+
414+
.. literalinclude:: projects.py
415+
:start-after: # pipeline get
416+
:end-before: # end pipeline get
417+
418+
Retry the failed builds for a pipeline:
419+
420+
.. literalinclude:: projects.py
421+
:start-after: # pipeline retry
422+
:end-before: # end pipeline retry
423+
424+
Cancel builds in a pipeline:
425+
426+
.. literalinclude:: projects.py
427+
:start-after: # pipeline cancel
428+
:end-before: # end pipeline cancel
398429
Services
399430
--------
400431

gitlab/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class Gitlab(object):
102102
project_members (ProjectMemberManager): Manager for GitLab projects
103103
members
104104
project_notes (ProjectNoteManager): Manager for GitLab projects notes
105+
project_pipelines (ProjectPipelineManager): Manager for GitLab projects
106+
pipelines
105107
project_tags (ProjectTagManager): Manager for GitLab projects tags
106108
project_mergerequest_notes (ProjectMergeRequestNoteManager): Manager
107109
for GitLab notes on merge requests
@@ -179,6 +181,7 @@ def __init__(self, url, private_token=None, email=None, password=None,
179181
self.project_issues = ProjectIssueManager(self)
180182
self.project_members = ProjectMemberManager(self)
181183
self.project_notes = ProjectNoteManager(self)
184+
self.project_pipelines = ProjectPipelineManager(self)
182185
self.project_tags = ProjectTagManager(self)
183186
self.project_mergerequest_notes = ProjectMergeRequestNoteManager(self)
184187
self.project_mergerequests = ProjectMergeRequestManager(self)

gitlab/exceptions.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,27 @@ class GitlabTransferProjectError(GitlabOperationError):
7575
pass
7676

7777

78-
class GitlabBuildCancelError(GitlabOperationError):
78+
class GitlabCancelError(GitlabOperationError):
7979
pass
8080

8181

82-
class GitlabBuildRetryError(GitlabOperationError):
82+
class GitlabBuildCancelError(GitlabCancelError):
83+
pass
84+
85+
86+
class GitlabPipelineCancelError(GitlabCancelError):
87+
pass
88+
89+
90+
class GitlabRetryError(GitlabOperationError):
91+
pass
92+
93+
94+
class GitlabBuildRetryError(GitlabRetryError):
95+
pass
96+
97+
98+
class GitlabPipelineRetryError(GitlabRetryError):
8399
pass
84100

85101

gitlab/objects.py

+38
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,43 @@ class ProjectFileManager(BaseManager):
16101610
obj_cls = ProjectFile
16111611

16121612

1613+
class ProjectPipeline(GitlabObject):
1614+
_url = '/projects/%(project_id)s/pipelines'
1615+
canCreate = False
1616+
canUpdate = False
1617+
canDelete = False
1618+
1619+
def retry(self, **kwargs):
1620+
"""Retries failed builds in a pipeline.
1621+
1622+
Raises:
1623+
GitlabConnectionError: If the server cannot be reached.
1624+
GitlabPipelineRetryError: If the retry cannot be done.
1625+
"""
1626+
url = ('/projects/%(project_id)s/pipelines/%(id)s/retry' %
1627+
{'project_id': self.project_id, 'id': self.id})
1628+
r = self.gitlab._raw_post(url, data=None, content_type=None, **kwargs)
1629+
raise_error_from_response(r, GitlabPipelineRetryError, 201)
1630+
self._set_from_dict(r.json())
1631+
1632+
def cancel(self, **kwargs):
1633+
"""Cancel builds in a pipeline.
1634+
1635+
Raises:
1636+
GitlabConnectionError: If the server cannot be reached.
1637+
GitlabPipelineCancelError: If the retry cannot be done.
1638+
"""
1639+
url = ('/projects/%(project_id)s/pipelines/%(id)s/cancel' %
1640+
{'project_id': self.project_id, 'id': self.id})
1641+
r = self.gitlab._raw_post(url, data=None, content_type=None, **kwargs)
1642+
raise_error_from_response(r, GitlabPipelineRetryError, 200)
1643+
self._set_from_dict(r.json())
1644+
1645+
1646+
class ProjectPipelineManager(BaseManager):
1647+
obj_cls = ProjectPipeline
1648+
1649+
16131650
class ProjectSnippetNote(GitlabObject):
16141651
_url = '/projects/%(project_id)s/snippets/%(snippet_id)s/notes'
16151652
_constructorTypes = {'author': 'User'}
@@ -1804,6 +1841,7 @@ class Project(GitlabObject):
18041841
('mergerequests', ProjectMergeRequestManager, [('project_id', 'id')]),
18051842
('milestones', ProjectMilestoneManager, [('project_id', 'id')]),
18061843
('notes', ProjectNoteManager, [('project_id', 'id')]),
1844+
('pipelines', ProjectPipelineManager, [('project_id', 'id')]),
18071845
('services', ProjectServiceManager, [('project_id', 'id')]),
18081846
('snippets', ProjectSnippetManager, [('project_id', 'id')]),
18091847
('tags', ProjectTagManager, [('project_id', 'id')]),

0 commit comments

Comments
 (0)