'Fail to update gitlab CICD variable using gitlab API

I am exploring Gitlab APIs to work with CICD. For updating gitlab CICD variable, I use following API

PUT /projects/:id/variables/:key

here is the document regarding it. This API works perfect if the variable is unique for CICD. But If I use duplicate name variable with different environment_scope, it some time update my variable but most time fail to update. It throws following error

key: [MY_KEY] has already been taken

I checked in gitlab issues here but didn't found any proper solution regarding it. For reference, my gitlab version is GitLab Community Edition 12.8.1

Can anybody help me regarding this?.. Thanks in advance.



Solution 1:[1]

From the documentation found here, It appers you need to amend the follow to the end of the line:

--form "value=updated value"

So ultimately you will have:

PUT /projects/:id/variables/:key --form "value=updated value"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 The Letter M