Builds

Build triggers

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

Examples

List triggers:

triggers = gl.project_triggers.list(project_id=1)
# or
triggers = project.triggers.list()

Get a trigger:

trigger = gl.project_triggers.get(trigger_token, project_id=1)
# or
trigger = project.triggers.get(trigger_token)

Create a trigger:

trigger = gl.project_triggers.create({}, project_id=1)
# or
trigger = project.triggers.create({})

Remove a trigger:

gl.project_triggers.delete(trigger_token)
# or
project.triggers.delete()
# or
trigger.delete()

Build variables

You can associate variables to builds to modify the build script behavior.

Examples

List variables:

variables = gl.project_variables.list(project_id=1)
# or
variables = project.variables.list()

Get a variable:

var = gl.project_variables.get(var_key, project_id=1)
# or
var = project.variables.get(var_key)

Create a variable:

var = gl.project_variables.create({'key': 'key1', 'value': 'value1'},
                                  project_id=1)
# or
var = project.variables.create({'key': 'key1', 'value': 'value1'})

Update a variable value:

var.value = 'new_value'
var.save()

Remove a variable:

gl.project_variables.delete(var_key)
# or
project.variables.delete()
# or
var.delete()

Builds

Builds are associated to projects and commits. They provide information on the build that have been run, and methods to manipulate those builds.

Examples

Build are usually automatically triggered, but you can explicitly trigger a new build:

Trigger a new build on a project:

p = gl.projects.get(project_id)
p.trigger_build('master', trigger_token,
                {'extra_var1': 'foo', 'extra_var2': 'bar'})

List builds for the project:

builds = gl.project_builds.list(project_id=1)
# or
builds = project.builds.list()

To list builds for a specific commit, create a ProjectCommit object and use its builds method:

commit = gl.project_commits.get(commit_sha, project_id=1)
builds = commit.builds()

Get a build:

build = gl.project_builds.get(build_id, project_id=1)
# or
project.builds.get(build_id)

Get a build artifacts:

build.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:

class Foo(object):
    def __init__(self):
        self._fd = open('artifacts.zip', 'wb')

    def __call__(self, chunk):
        self._fd.write(chunk)

target = Foo()
build.artifacts(streamed=True, action=target)
del(target)  # flushes data on disk

Mark a build artifact as kept when expiration is set:

build.keep_artifacts()

Get a build trace:

build.trace()

Warning

Traces are entirely stored in memory unless you use the streaming feature. See the artifacts example.

Cancel/retry a build:

build.cancel()
build.retry()

Play (trigger) a build:

build.play()

Erase a build (artifacts and trace):

build.erase()