|
| 1 | +############### |
| 2 | +CI/CD Variables |
| 3 | +############### |
| 4 | + |
| 5 | +You can configure variables at the instance-level (admin only), or associate |
| 6 | +variables to projects and groups, to modify pipeline/job scripts behavior. |
| 7 | + |
| 8 | + |
| 9 | +Instance-level variables |
| 10 | +======================== |
| 11 | + |
| 12 | +This endpoint requires admin access. |
| 13 | + |
| 14 | +Reference |
| 15 | +--------- |
| 16 | + |
| 17 | +* v4 API |
| 18 | + |
| 19 | + + :class:`gitlab.v4.objects.Variable` |
| 20 | + + :class:`gitlab.v4.objects.VariableManager` |
| 21 | + + :attr:`gitlab.Gitlab.variables` |
| 22 | + |
| 23 | +* GitLab API |
| 24 | + |
| 25 | + + https://docs.gitlab.com/ce/api/instance_level_ci_variables.html |
| 26 | + |
| 27 | +Examples |
| 28 | +-------- |
| 29 | + |
| 30 | +List all instance variables:: |
| 31 | + |
| 32 | + variables = gl.variables.list() |
| 33 | + |
| 34 | +Get an instance variable by key:: |
| 35 | + |
| 36 | + variable = gl.variables.get('key_name') |
| 37 | + |
| 38 | +Create an instance variable:: |
| 39 | + |
| 40 | + variable = gl.variables.create({'key': 'key1', 'value': 'value1'}) |
| 41 | + |
| 42 | +Update a variable value:: |
| 43 | + |
| 44 | + variable.value = 'new_value' |
| 45 | + variable.save() |
| 46 | + |
| 47 | +Remove a variable:: |
| 48 | + |
| 49 | + gl.variables.delete('key_name') |
| 50 | + # or |
| 51 | + variable.delete() |
| 52 | + |
| 53 | +Projects and groups variables |
| 54 | +============================= |
| 55 | + |
| 56 | +Reference |
| 57 | +--------- |
| 58 | + |
| 59 | +* v4 API |
| 60 | + |
| 61 | + + :class:`gitlab.v4.objects.ProjectVariable` |
| 62 | + + :class:`gitlab.v4.objects.ProjectVariableManager` |
| 63 | + + :attr:`gitlab.v4.objects.Project.variables` |
| 64 | + + :class:`gitlab.v4.objects.GroupVariable` |
| 65 | + + :class:`gitlab.v4.objects.GroupVariableManager` |
| 66 | + + :attr:`gitlab.v4.objects.Group.variables` |
| 67 | + |
| 68 | +* GitLab API |
| 69 | + |
| 70 | + + https://docs.gitlab.com/ce/api/instance_level_ci_variables.html |
| 71 | + + https://docs.gitlab.com/ce/api/project_level_variables.html |
| 72 | + + https://docs.gitlab.com/ce/api/group_level_variables.html |
| 73 | + |
| 74 | +Examples |
| 75 | +-------- |
| 76 | + |
| 77 | +List variables:: |
| 78 | + |
| 79 | + p_variables = project.variables.list() |
| 80 | + g_variables = group.variables.list() |
| 81 | + |
| 82 | +Get a variable:: |
| 83 | + |
| 84 | + p_var = project.variables.get('key_name') |
| 85 | + g_var = group.variables.get('key_name') |
| 86 | + |
| 87 | +Create a variable:: |
| 88 | + |
| 89 | + var = project.variables.create({'key': 'key1', 'value': 'value1'}) |
| 90 | + var = group.variables.create({'key': 'key1', 'value': 'value1'}) |
| 91 | + |
| 92 | +Update a variable value:: |
| 93 | + |
| 94 | + var.value = 'new_value' |
| 95 | + var.save() |
| 96 | + |
| 97 | +Remove a variable:: |
| 98 | + |
| 99 | + project.variables.delete('key_name') |
| 100 | + group.variables.delete('key_name') |
| 101 | + # or |
| 102 | + var.delete() |
0 commit comments