From dc2a853f386365c112a992ab45ab64bccb4e3b6e Mon Sep 17 00:00:00 2001 From: Keith Wansbrough Date: Wed, 10 Jan 2018 19:59:46 +0000 Subject: [PATCH 1/3] Add manager for jobs within a pipeline. --- gitlab/v4/objects.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index d7bb3d590..1aa4731f5 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -1883,6 +1883,8 @@ def raw(self, file_path, ref, streamed=False, action=None, chunk_size=1024, class ProjectPipeline(RESTObject): + _managers = (('jobs', 'ProjectPipelineJobManager'), ) + @cli.register_custom_action('ProjectPipeline') @exc.on_http_error(exc.GitlabPipelineCancelError) def cancel(self, **kwargs): @@ -1940,6 +1942,12 @@ def create(self, data, **kwargs): return CreateMixin.create(self, data, path=path, **kwargs) +class ProjectPipelineJobManager(RetrieveMixin, RESTManager): + _path = '/projects/%(project_id)s/pipelines/%(pipeline_id)s/jobs' + _obj_cls = ProjectJob + _from_parent_attrs = {'project_id': 'project_id', 'pipeline_id': 'id'} + + class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject): pass From cfad2698869de1310c339fdb9aadda7044e2b599 Mon Sep 17 00:00:00 2001 From: Keith Wansbrough Date: Mon, 15 Jan 2018 10:31:30 +0000 Subject: [PATCH 2/3] Add documentation for pipeline jobs. --- docs/gl_objects/builds.py | 12 ++++++++++-- docs/gl_objects/builds.rst | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/gl_objects/builds.py b/docs/gl_objects/builds.py index ba4b22bff..a5d20059a 100644 --- a/docs/gl_objects/builds.py +++ b/docs/gl_objects/builds.py @@ -55,10 +55,18 @@ builds = commit.builds() # end commit list -# get +# pipeline list get +# v4 only +project = gl.projects.get(project_id) +pipeline = project.pipelines.get(pipeline_id) +jobs = pipeline.jobs.list() # gets all jobs in pipeline +job = pipeline.jobs.get(job_id) # gets one job from pipeline +# end pipeline list get + +# get job project.builds.get(build_id) # v3 project.jobs.get(job_id) # v4 -# end get +# end get job # artifacts build_or_job.artifacts() diff --git a/docs/gl_objects/builds.rst b/docs/gl_objects/builds.rst index 1c95eb16e..b0f3e22f0 100644 --- a/docs/gl_objects/builds.rst +++ b/docs/gl_objects/builds.rst @@ -122,8 +122,9 @@ Remove a variable: Builds/Jobs =========== -Builds/Jobs are associated to projects and commits. They provide information on -the builds/jobs that have been run, and methods to manipulate them. +Builds/Jobs are associated to projects, pipelines and commits. They provide +information on the builds/jobs that have been run, and methods to manipulate +them. Reference --------- @@ -169,11 +170,20 @@ To list builds for a specific commit, create a :start-after: # commit list :end-before: # end commit list +To list builds for a specific pipeline or get a single job within a specific +pipeline, create a +:class:`~gitlab.v4.objects.ProjectPipeline` object and use its +:attr:`~gitlab.v4.objects.ProjectPipeline.jobs` method (v4 only): + +.. literalinclude:: builds.py + :start-after: # pipeline list get + :end-before: # end pipeline list get + Get a job: .. literalinclude:: builds.py - :start-after: # get - :end-before: # end get + :start-after: # get job + :end-before: # end get job Get a job artifact: From de3f583e5741f8887e20d1d3b60e7c03ad85ed4d Mon Sep 17 00:00:00 2001 From: Keith Wansbrough Date: Mon, 15 Jan 2018 11:00:26 +0000 Subject: [PATCH 3/3] Support pipeline jobs get, and distinguish the job classes. Review markup: better to use a distinct ProjectPipelineJob rather than sharing ProjectJob. This is consistent with the other objects and managers. --- gitlab/v4/objects.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 1aa4731f5..e4a544730 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -1942,9 +1942,13 @@ def create(self, data, **kwargs): return CreateMixin.create(self, data, path=path, **kwargs) -class ProjectPipelineJobManager(RetrieveMixin, RESTManager): +class ProjectPipelineJob(ProjectJob): + pass + + +class ProjectPipelineJobManager(GetFromListMixin, RESTManager): _path = '/projects/%(project_id)s/pipelines/%(pipeline_id)s/jobs' - _obj_cls = ProjectJob + _obj_cls = ProjectPipelineJob _from_parent_attrs = {'project_id': 'project_id', 'pipeline_id': 'id'}