Creating a group level variable using the GitLab API

Viewed 60

I'm trying to automate the update of a group level variable via the GitLab API

I want to provide the value of this variable using a file. To do this I need to specify "variable_type=file". However, the API still requires "value" to be set. So, I'm going round in circles getting errors. How can I only provide a file if "value" still needs to be set?

curl --request $method --header "PRIVATE-TOKEN: ${MY_TOKEN}"  \
 "https://gitlab.com/api/v4/groups/123456/variables" --form "key=TRIGGER_TOKENS" --form file=@./triggertokens.txt --form "masked=true" \
 --form "protected=false" --form "variable_type=file" --form "environment_scope=my_env" --form "value= "

The above returns:

{"message":{"value":["is invalid"]}}%                                                                                                                                                                                                    

Thanks in advance :-)

1 Answers

--form file=@./triggertokens.txt

There is no actual file field in the form/API. Use the value form field to pass the contents of the file variable.

Related