Group variable API does not set environment scope
Summary
Using GitLab's REST API for creating or updating group variable. In my case, I need to configure the environment_scope. However, the API does not set the environment_scope.
It seems to be a regression. Based on this github issue discussion, it appears to have worked at least in version 16.7.10.
Steps to reproduce
- Create a group and ensure at least premium and ultimate license is available because setting environment scope in group variable is not available in free version.
# check gitlab license
$ curl --request GET --header "PRIVATE-TOKEN: ***" "http://localhost/api/v4/license" | jq .
{
"id": 1,
"plan": "ultimate",
...
}
- Create a group variable using API with an environment scope
# GitLab API for creating a group level CI variable with environment scope defined
$ curl --request POST --header 'PRIVATE-TOKEN: ***' --form "key=TEST_VAR" --form "value=TEST_VALUE" --form "environment=review/*" --url 'http://localhost/api/v4/groups/test-group/variables' | jq .
{
"variable_type": "env_var",
"key": "TEST_VAR",
"value": "TEST_VALUE",
"hidden": false,
"protected": false,
"masked": false,
"raw": false,
"environment_scope": "*",
"description": null
}
Notice that the variable was created with default environment_scope set to * instead of review/*.
- Use the API to update the variable's value and
environment_scope.
# GitLab API for updating the previous group level CI variable's value and environment scope
$ curl --request PUT --header 'PRIVATE-TOKEN: ***' --form "value=TEST_UPDATED_VALUE" --form "environment=review/*" --url 'http://localhost/api/v4/groups/test-group/variables/TEST_VAR' | jq .
{
"variable_type": "env_var",
"key": "TEST_VAR",
"value": "TEST_UPDATED_VALUE",
"hidden": false,
"protected": false,
"masked": false,
"raw": false,
"environment_scope": "*",
"description": null
}
Notice the variable value has been updated but the environment_scope remains unchanged.
Example Project
n/a
What is the current bug behavior?
Using the API, group variable's environment scope cannot be configured.
What is the expected correct behavior?
Using the API, group variable's environment scope should be configurable.
Relevant logs and/or screenshots
n/a
Output of checks
n/a
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)(we will only investigate if the tests are passing)
Possible fixes
Patch release information for backports
If the bug fix needs to be backported in a patch release to a version under the maintenance policy, please follow the steps on the patch release runbook for GitLab engineers.
Refer to the internal "Release Information" dashboard for information about the next patch release, including the targeted versions, expected release date, and current status.
High-severity bug remediation
To remediate high-severity issues requiring an internal release for single-tenant SaaS instances, refer to the internal release process for engineers.