diff --git a/docs/gl_objects/builds.py b/docs/gl_objects/builds.py index e125b39eb..5ca55db8b 100644 --- a/docs/gl_objects/builds.py +++ b/docs/gl_objects/builds.py @@ -1,13 +1,16 @@ # var list -variables = project.variables.list() +p_variables = project.variables.list() +g_variables = group.variables.list() # end var list # var get -var = project.variables.get(var_key) +p_var = project.variables.get(var_key) +g_var = group.variables.get(var_key) # end var get # var create var = project.variables.create({'key': 'key1', 'value': 'value1'}) +var = group.variables.create({'key': 'key1', 'value': 'value1'}) # end var create # var update @@ -17,6 +20,7 @@ # var delete project.variables.delete(var_key) +group.variables.delete(var_key) # or var.delete() # end var delete diff --git a/docs/gl_objects/builds.rst b/docs/gl_objects/builds.rst index 52bdb1ace..1c95eb16e 100644 --- a/docs/gl_objects/builds.rst +++ b/docs/gl_objects/builds.rst @@ -56,11 +56,11 @@ Remove a trigger: :start-after: # trigger delete :end-before: # end trigger delete -Project variables -================= +Projects and groups variables +============================= -You can associate variables to projects to modify the build/job script -behavior. +You can associate variables to projects and groups to modify the build/job +scripts behavior. Reference --------- @@ -70,6 +70,9 @@ Reference + :class:`gitlab.v4.objects.ProjectVariable` + :class:`gitlab.v4.objects.ProjectVariableManager` + :attr:`gitlab.v4.objects.Project.variables` + + :class:`gitlab.v4.objects.GroupVariable` + + :class:`gitlab.v4.objects.GroupVariableManager` + + :attr:`gitlab.v4.objects.Group.variables` * v3 API @@ -78,7 +81,10 @@ Reference + :attr:`gitlab.v3.objects.Project.variables` + :attr:`gitlab.Gitlab.project_variables` -* GitLab API: https://docs.gitlab.com/ce/api/project_level_variables.html +* GitLab API + + + https://docs.gitlab.com/ce/api/project_level_variables.html + + https://docs.gitlab.com/ce/api/group_level_variables.html Examples -------- diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 3b1eb9175..92c4543df 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -2185,6 +2185,18 @@ class GroupProjectManager(GetFromListMixin, RESTManager): 'ci_enabled_first') +class GroupVariable(SaveMixin, ObjectDeleteMixin, RESTObject): + _id_attr = 'key' + + +class GroupVariableManager(CRUDMixin, RESTManager): + _path = '/groups/%(group_id)s/variables' + _obj_cls = GroupVariable + _from_parent_attrs = {'group_id': 'id'} + _create_attrs = (('key', 'value'), ('protected',)) + _update_attrs = (('key', 'value'), ('protected',)) + + class Group(SaveMixin, ObjectDeleteMixin, RESTObject): _short_print_attr = 'name' _managers = ( @@ -2193,6 +2205,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): ('notificationsettings', 'GroupNotificationSettingsManager'), ('projects', 'GroupProjectManager'), ('issues', 'GroupIssueManager'), + ('variables', 'GroupVariableManager'), ) @cli.register_custom_action('Group', ('to_project_id', )) diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index 8cc088644..0cbea33d8 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -170,6 +170,18 @@ settings = group2.notificationsettings.get() assert(settings.level == 'disabled') +# group variables +group1.variables.create({'key': 'foo', 'value': 'bar'}) +g_v = group1.variables.get('foo') +assert(g_v.value == 'bar') +g_v.value = 'baz' +g_v.save() +g_v = group1.variables.get('foo') +assert(g_v.value == 'baz') +assert(len(group1.variables.list()) == 1) +g_v.delete() +assert(len(group1.variables.list()) == 0) + # hooks hook = gl.hooks.create({'url': 'http://whatever.com'}) assert(len(gl.hooks.list()) == 1)