Skip to content

Commit fcccfbd

Browse files
author
Gauvain Pocentek
committed
Merge branch 'group-variables'
2 parents 0e0d4ae + eb191df commit fcccfbd

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

docs/gl_objects/builds.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# var list
2-
variables = project.variables.list()
2+
p_variables = project.variables.list()
3+
g_variables = group.variables.list()
34
# end var list
45

56
# var get
6-
var = project.variables.get(var_key)
7+
p_var = project.variables.get(var_key)
8+
g_var = group.variables.get(var_key)
79
# end var get
810

911
# var create
1012
var = project.variables.create({'key': 'key1', 'value': 'value1'})
13+
var = group.variables.create({'key': 'key1', 'value': 'value1'})
1114
# end var create
1215

1316
# var update
@@ -17,6 +20,7 @@
1720

1821
# var delete
1922
project.variables.delete(var_key)
23+
group.variables.delete(var_key)
2024
# or
2125
var.delete()
2226
# end var delete

docs/gl_objects/builds.rst

+11-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ Remove a trigger:
5656
:start-after: # trigger delete
5757
:end-before: # end trigger delete
5858

59-
Project variables
60-
=================
59+
Projects and groups variables
60+
=============================
6161

62-
You can associate variables to projects to modify the build/job script
63-
behavior.
62+
You can associate variables to projects and groups to modify the build/job
63+
scripts behavior.
6464

6565
Reference
6666
---------
@@ -70,6 +70,9 @@ Reference
7070
+ :class:`gitlab.v4.objects.ProjectVariable`
7171
+ :class:`gitlab.v4.objects.ProjectVariableManager`
7272
+ :attr:`gitlab.v4.objects.Project.variables`
73+
+ :class:`gitlab.v4.objects.GroupVariable`
74+
+ :class:`gitlab.v4.objects.GroupVariableManager`
75+
+ :attr:`gitlab.v4.objects.Group.variables`
7376

7477
* v3 API
7578

@@ -78,7 +81,10 @@ Reference
7881
+ :attr:`gitlab.v3.objects.Project.variables`
7982
+ :attr:`gitlab.Gitlab.project_variables`
8083

81-
* GitLab API: https://docs.gitlab.com/ce/api/project_level_variables.html
84+
* GitLab API
85+
86+
+ https://docs.gitlab.com/ce/api/project_level_variables.html
87+
+ https://docs.gitlab.com/ce/api/group_level_variables.html
8288

8389
Examples
8490
--------

gitlab/v4/objects.py

+13
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,18 @@ class GroupProjectManager(GetFromListMixin, RESTManager):
21852185
'ci_enabled_first')
21862186

21872187

2188+
class GroupVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
2189+
_id_attr = 'key'
2190+
2191+
2192+
class GroupVariableManager(CRUDMixin, RESTManager):
2193+
_path = '/groups/%(group_id)s/variables'
2194+
_obj_cls = GroupVariable
2195+
_from_parent_attrs = {'group_id': 'id'}
2196+
_create_attrs = (('key', 'value'), ('protected',))
2197+
_update_attrs = (('key', 'value'), ('protected',))
2198+
2199+
21882200
class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
21892201
_short_print_attr = 'name'
21902202
_managers = (
@@ -2193,6 +2205,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
21932205
('notificationsettings', 'GroupNotificationSettingsManager'),
21942206
('projects', 'GroupProjectManager'),
21952207
('issues', 'GroupIssueManager'),
2208+
('variables', 'GroupVariableManager'),
21962209
)
21972210

21982211
@cli.register_custom_action('Group', ('to_project_id', ))

tools/python_test_v4.py

+12
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@
170170
settings = group2.notificationsettings.get()
171171
assert(settings.level == 'disabled')
172172

173+
# group variables
174+
group1.variables.create({'key': 'foo', 'value': 'bar'})
175+
g_v = group1.variables.get('foo')
176+
assert(g_v.value == 'bar')
177+
g_v.value = 'baz'
178+
g_v.save()
179+
g_v = group1.variables.get('foo')
180+
assert(g_v.value == 'baz')
181+
assert(len(group1.variables.list()) == 1)
182+
g_v.delete()
183+
assert(len(group1.variables.list()) == 0)
184+
173185
# hooks
174186
hook = gl.hooks.create({'url': 'http://whatever.com'})
175187
assert(len(gl.hooks.list()) == 1)

0 commit comments

Comments
 (0)