Im having problems running an API call towards GitLab to update a group variable in our GitLab instance.
Running the command below works fine when running locally, but Im having issue running the same command with GitLab pipelines.
curl --request PUT
--header "PRIVATE-TOKEN: $GITLAB_API_TOKEN"
--header "Content-Type: application/json"
--data "$token"
"https://$GILAB_URL/api/v4/groups/$GITLAB_GROUP/variables/VARIABLE"
Have also tried
curl --request PUT --header "PRIVATE-TOKEN: $GITLAB_API_TOKEN" --header "Content-Type: application/json" --data '{"value": "'$token'"}' "https://$GILAB_URL/api/v4/groups/$GITLAB_GROUP/variables/VARIABLE"
Error message from GitLab pipelines:
{"message":{"value":["is invalid"]}}
It works when I hardcode the token value in the curl command aswell.
Value of $token "similar to this"
eyJ9ZXGiOiIyIiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYiLCJraWQiOiJLNlh5ZFJFZlhJTmNuaDM1WVRsTlFZajNUSDBKQk1MN0VLRWJCLWIz0ENZIn0.eyJzdWIiOiJjMy1vaWRjL2NhdGNoLWFsbCIsInNjcCI6ImFwcGxpZWFiTcGVybWlzc2lvbnMvZ3JvdXBzOlwiZDAzCjUyOTctMWQ0ZS00RGFiLTlkNDEtNDgwZDBkMDk3KuWRiXCIsXCI1OTYzNGRjOC04YzMwLTRlMGUtOThkNC05NDFhOGQ5MTgxNWJcIiwiLCJhdWQiOlsiamZydEAqIiwiamChY0AqIiwiamZtY0AqIiwiamZtZEAqIiwiamZldnRAKiIsImpmeGZlckAqIiwiamZsbmtABosYImpmaW50QCoiLCJqZndrc0AqIl0sImlzcyI6ImpmYWNAMDFlcHk2Zm1xcXJtNWQwdjRyNWdhZTE5cmIiLCJleHAiOjE3MzAzNjU0NjUsImlhdCI6MTczMDM2NTE2NSwAPpIjoiMDdjZTlmZDQtOWQwYS00YmEwLTk3OTYtNWRhZGNlYmQxYTc2In0.FyQ2f1QIRkX3ZeXX2hkgtk1ilZxFFCh6CnRPEufyvaXDLeryvMRGjW73phj45aQiO9MWEHPSDbFVQuKTtxgZUSqZDY7V0osz28OMW5if1tMgOlHkrjre06K37Afbi8UkKvNA-fLn8s0eMut8a6sotKagH8Z5BACG4ziLY7TTQfUTIZSOxMNHyWRrbdSvBL-Nh-4FziCaAY6WdojeZNOpoWp9PLJQrYwEpKrBJ08IYT6Ie5JP2IdFga5ZP4lqc6pLPXfnnU1MBn94HdUVlhFfZUYmlJpD_U4mSA8L5aBgrrw7epUgNRKhCHdJoOhONoCgli5WmqR9NvLBEP53Q5yvCB
Any help here would be appreciated.
Thanks!
- Hardcoding token value in curl command by replacing it with $token
- Works locally on (mac) / gitlab runners use ubuntu.
2
Answers
Got it work now. The issue was that my token had a special characther "=" so I had to encode it before.
Thanks for your help!
Try below that will work
You used single quote within single quote without escape character.