"Show Project-level variable details" API call returns only one result for multiple variables with the same name
Hello. I checked twice and haven't found any related issue.
Summary
I run into a problem with using v4 api to get Project-level variable details
. This call returns only one result in case of many project variables with the same name, but with different environment_scope
parameters.
Method documentation https://docs.gitlab.com/ee/api/project_level_variables.html#show-variable-details
Steps to reproduce
- Add multiple project variables with the same name, but with different
environment_scope
parameters. - Get access token and request variable details
curl -sH "PRIVATE-TOKEN: ${GITLAB_TOKEN}" "https://gitlab.com/api/v4/projects/13745804/variables/TEST_VAR"|jq .
{
"variable_type": "env_var",
"key": "TEST_VAR",
"value": "ddd",
"protected": false,
"masked": false,
"environment_scope": "*"
}
- only one result returned
- But there are more variables with the same name
curl -sH "PRIVATE-TOKEN: ${GITLAB_TOKEN}" "https://gitlab.com/api/v4/projects/13745804/variables"|jq .
[
{
"variable_type": "env_var",
"key": "TEST_VAR",
"value": "123",
"protected": false,
"masked": false,
"environment_scope": "env1"
},
{
"variable_type": "env_var",
"key": "TEST_VAR",
"value": "321",
"protected": false,
"masked": false,
"environment_scope": "env2"
},
{
"variable_type": "env_var",
"key": "TEST_VAR",
"value": "456",
"protected": false,
"masked": false,
"environment_scope": "env3"
},
{
"variable_type": "env_var",
"key": "TEST_VAR",
"value": "ddd",
"protected": false,
"masked": false,
"environment_scope": "*"
}
]
Example Project
https://gitlab.com/Nklya/test-api
What is the current bug behavior?
Only one variable details returned
What is the expected correct behavior?
All environment variables with the same name return
Relevant logs and/or screenshots
My example project variables
Output of checks
This bug happens on GitLab.com too
Results of GitLab environment info
Tested on GitLab.com and private GitLab Enterprise Edition 11.11
Results of GitLab application Check
Not applicable, as bug reproduced on GitLab.com
Possible fixes
For now, I found a workaround with requesting all variables with https://docs.gitlab.com/ce/api/project_level_variables.html#list-project-variables and then check all of them.