CI/CD variables
Configuring CI/CD variables¶
CI/CD variables exist at three scopes: instance
(gitlab_settings_instance.ci_variables, documented in
Instance Administration), group, and
project. Group and project variables are unique by key plus
environment_scope — each declared (key, scope) pair is reconciled
independently and never cross-matched with another scope.
Variable values are write-only secrets
value is write-only and secret: never compared, displayed, or diffed.
It is carried on every write (GitLab requires it on update), and
force_secret_update: true forces a rotation write when nothing else
drifted — declare the new value with the flag, apply, then remove the flag.
Example variables definition¶
gitlab_settings_groups:
- path: platform
variables:
- key: REGISTRY_TOKEN
value: "{{ vault_registry_token }}"
protected: true
masked: true
gitlab_settings_projects:
- path: platform/service
variables:
- key: DEPLOY_TOKEN
value: "{{ vault_deploy_token_default }}"
- key: DEPLOY_TOKEN
value: "{{ vault_deploy_token_production }}"
environment_scope: production
protected: true
- key: OBSOLETE_VAR
state: absent
CI/CD Variables Spec¶
GitLab API reference
GitLab's API documentation defines the fields:
|
Variable name. Together with | Example: |
|
Scope the variable applies to. Part of the identity: the same Default: | Example: |
|
Required when the variable's | Example: |
|
Rewrite the value on an existing variable even without other drift. Use for rotation, then remove. Default: | Example: |
|
Limit the variable to protected branches and tags. Reconciles with drift detection. | Example: |
|
Mask the variable value in job logs. Reconciles with drift detection. | Example: |
|
Disable variable expansion when | Example: |
|
Can be one of: | Example: |
|
Human-readable variable description. Reconciles with drift detection. | Example: |
|
Hide the variable after creation. GitLab reports this as | Example: |
|
Lifecycle per (key, scope) pair. Can be one of: Default: | Example: |