GitLab EE API Project Variables DELETE action on KEY with multiple environment scope variables
Summary
GitLab EE features Project Level variables with environment support (Project -> Settings -> CI/CD -> Variables). This means that you can essentially have multiple variables with the same key, if they are assigned to different environment scopes. API doc: https://docs.gitlab.com/ee/api/project_level_variables.html
GitLab EE API supports CRUD operations on the Project Variables, however the DELETE action only takes "KEY" as argument. This means when have multiple Project Variables with the same KEY (just for a different environment scope), then the DELETE action deletes a random KEY.
Steps to reproduce
Create variables:
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/variables" --form "key=NEW_VARIABLE" --form "value=new value"
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/variables" --form "key=NEW_VARIABLE" --form "value=new value" --form "environment_scope=test"
Delete a variable:
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/variables/NEW_VARIABLE"
What is the current bug behavior?
Since you are unable to specify which key & environment_scope project variable to delete, it appears that the variable is deleted by random choice.
What is the expected correct behavior?
Being able to specify either the internal id of the project level variable or variable name with environment scope for deletion in the GitLab EE v4 API.
Possible fixes
Add environment_scope to DELETE request parameters.