Skip to content

Latest commit

 

History

History
230 lines (155 loc) · 5 KB

File metadata and controls

230 lines (155 loc) · 5 KB

Jobs (v4 API) / Builds (v3 API)

Build and job are two classes representing the same object. Builds are used in v3 API, jobs in v4 API.

Triggers

Triggers provide a way to interact with the GitLab CI. Using a trigger a user or an application can run a new build/job for a specific commit.

Reference

Examples

List triggers:

.. literalinclude:: builds.py
   :start-after: # trigger list
   :end-before: # end trigger list

Get a trigger:

.. literalinclude:: builds.py
   :start-after: # trigger get
   :end-before: # end trigger get

Create a trigger:

.. literalinclude:: builds.py
   :start-after: # trigger create
   :end-before: # end trigger create

Remove a trigger:

.. literalinclude:: builds.py
   :start-after: # trigger delete
   :end-before: # end trigger delete

Projects and groups variables

You can associate variables to projects and groups to modify the build/job scripts behavior.

Reference

Examples

List variables:

.. literalinclude:: builds.py
   :start-after: # var list
   :end-before: # end var list

Get a variable:

.. literalinclude:: builds.py
   :start-after: # var get
   :end-before: # end var get

Create a variable:

.. literalinclude:: builds.py
   :start-after: # var create
   :end-before: # end var create

Update a variable value:

.. literalinclude:: builds.py
   :start-after: # var update
   :end-before: # end var update

Remove a variable:

.. literalinclude:: builds.py
   :start-after: # var delete
   :end-before: # end var delete

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.

Reference

Examples

Jobs are usually automatically triggered, but you can explicitly trigger a new job:

Trigger a new job on a project:

.. literalinclude:: builds.py
   :start-after: # trigger run
   :end-before: # end trigger run

List jobs for the project:

.. literalinclude:: builds.py
   :start-after: # list
   :end-before: # end list

To list builds for a specific commit, create a :class:`~gitlab.v3.objects.ProjectCommit` object and use its :attr:`~gitlab.v3.objects.ProjectCommit.builds` method (v3 only):

.. literalinclude:: builds.py
   :start-after: # commit list
   :end-before: # end commit list

Get a job:

.. literalinclude:: builds.py
   :start-after: # get
   :end-before: # end get

Get a job artifact:

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

Warning

Artifacts are entirely stored in memory in this example.

You can download artifacts as a stream. Provide a callable to handle the stream:

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

Mark a job artifact as kept when expiration is set:

.. literalinclude:: builds.py
   :start-after: # keep artifacts
   :end-before: # end keep artifacts

Get a job trace:

.. literalinclude:: builds.py
   :start-after: # trace
   :end-before: # end trace

Warning

Traces are entirely stored in memory unless you use the streaming feature. See :ref:`the artifacts example <streaming_example>`.

Cancel/retry a job:

.. literalinclude:: builds.py
   :start-after: # retry
   :end-before: # end retry

Play (trigger) a job:

.. literalinclude:: builds.py
   :start-after: # play
   :end-before: # end play

Erase a job (artifacts and trace):

.. literalinclude:: builds.py
   :start-after: # erase
   :end-before: # end erase