File: variables.rst

package info (click to toggle)
python-gitlab 1%3A4.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,048 kB
  • sloc: python: 24,168; makefile: 171; ruby: 27; javascript: 3
file content (135 lines) | stat: -rw-r--r-- 3,317 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
###############
CI/CD Variables
###############

You can configure variables at the instance-level (admin only), or associate
variables to projects and groups, to modify pipeline/job scripts behavior.

.. warning::

    Please always follow GitLab's `rules for CI/CD variables`_, especially for values
    in masked variables. If you do not, your variables may silently fail to save.

.. _rules for CI/CD variables: https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-project

Instance-level variables
========================

This endpoint requires admin access.

Reference
---------

* v4 API

  + :class:`gitlab.v4.objects.Variable`
  + :class:`gitlab.v4.objects.VariableManager`
  + :attr:`gitlab.Gitlab.variables`

* GitLab API

  + https://docs.gitlab.com/ce/api/instance_level_ci_variables.html

Examples
--------

List all instance variables::

    variables = gl.variables.list()

Get an instance variable by key::

    variable = gl.variables.get('key_name')

Create an instance variable::

    variable = gl.variables.create({'key': 'key1', 'value': 'value1'})

Update a variable value::

    variable.value = 'new_value'
    variable.save()

Remove a variable::

    gl.variables.delete('key_name')
    # or
    variable.delete()

Projects and groups variables
=============================

Reference
---------

* v4 API

  + :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`

* GitLab API

  + https://docs.gitlab.com/ce/api/instance_level_ci_variables.html
  + https://docs.gitlab.com/ce/api/project_level_variables.html
  + https://docs.gitlab.com/ce/api/group_level_variables.html

Examples
--------

List variables::

    p_variables = project.variables.list()
    g_variables = group.variables.list()

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.