Skip to content

Commit c378817

Browse files
JohnVillalovosnejch
authored andcommitted
docs: variables: add note about filter for updating
Add a note about using `filter` when updating a variable. Closes: #2835 Closes: #1387 Closes: #1125
1 parent 6fedfa5 commit c378817

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/gl_objects/variables.rst

+25
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,46 @@ Get a variable::
9090
p_var = project.variables.get('key_name')
9191
g_var = group.variables.get('key_name')
9292

93+
.. note::
94+
95+
If there are multiple variables with the same key, use ``filter`` to select
96+
the correct ``environment_scope``. See the GitLab API docs for more
97+
information.
98+
9399
Create a variable::
94100

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

104+
.. note::
105+
106+
If a variable with the same key already exists, the new variable must have a
107+
different ``environment_scope``. Otherwise, GitLab returns a message similar
108+
to: ``VARIABLE_NAME has already been taken``. See the GitLab API docs for
109+
more information.
110+
98111
Update a variable value::
99112

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

118+
.. note::
119+
120+
If there are multiple variables with the same key, use ``filter`` to select
121+
the correct ``environment_scope``. See the GitLab API docs for more
122+
information.
123+
105124
Remove a variable::
106125

107126
project.variables.delete('key_name')
108127
group.variables.delete('key_name')
109128
# or
110129
var.delete()
130+
131+
.. note::
132+
133+
If there are multiple variables with the same key, use ``filter`` to select
134+
the correct ``environment_scope``. See the GitLab API docs for more
135+
information.

0 commit comments

Comments
 (0)