Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/gl_objects/variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,46 @@ Get a variable::
p_var = project.variables.get('key_name')
g_var = group.variables.get('key_name')

.. note::

If there are multiple variables with the same key, use ``filter`` to select
the correct ``environment_scope``. See the GitLab API docs for more
information.

Create a variable::

var = project.variables.create({'key': 'key1', 'value': 'value1'})
var = group.variables.create({'key': 'key1', 'value': 'value1'})

.. note::

If a variable with the same key already exists, the new variable must have a
different ``environment_scope``. Otherwise, GitLab returns a message similar
to: ``VARIABLE_NAME has already been taken``. See the GitLab API docs for
more information.

Update a variable value::

var.value = 'new_value'
var.save()
# or
project.variables.update("key1", {"value": "new_value"})

.. note::

If there are multiple variables with the same key, use ``filter`` to select
the correct ``environment_scope``. See the GitLab API docs for more
information.

Remove a variable::

project.variables.delete('key_name')
group.variables.delete('key_name')
# or
var.delete()

.. note::

If there are multiple variables with the same key, use ``filter`` to select
the correct ``environment_scope``. See the GitLab API docs for more
information.