I see this blog, but it refers to a specific repository variable. I however, want to create/update a workspace variable. Will it be the same --data, but the URL will stop at the workspace?
Hey @Chris Fouts ,
thanks for reaching out to Community!
The endpoint to update workspace variables and repository variables is a little bit different:
PUT https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines_config/variables/{variable_uuid}
PUT https://api.bitbucket.org/2.0/workspaces/{workspace}/pipelines-config/variables/{variable_uuid}
While the endpoints are different, the request body (--data) is the same amongst those two endpoints.
I hope that helps! Should you have any questions, feel free to ask.
Thank you, @Chris Fouts !
Patrik S
Thanks @Patrik S I was able to create a workspace variable per you answer. However, I can't update it, and get no discernable error. I get the variable_uuid by
GET
https://api.bitbucket.org/2.0/workspaces/{workspace}/pipelines-config/variables?page=2
and see
{
"type": "pipeline_variable",
"uuid": "{f8278c5e-b42b-4fc7-8a47-d3bbb8f98808}",
"key": "TEST_VAR",
"value": "TEST_VALUE",
"secured": false,
"system": false,
"scope": "ACCOUNT"
},
So I do a
PUT https://api.bitbucket.org/2.0/workspaces/{workspace}/pipelines-config/variables/{f8278c5e-b42b-4fc7-8a47-d3bbb8f98808} \
--data '{
"key": "TEST_VAR",
"value: "NEW_VALUE",
"secured: false
}'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I opened a Bitbucket support ticket too where I give more information that I can't put here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Chris Fouts ,
I noticed you opened a support ticket but set it as resolved already.
I'll be sharing the same response here so it may be useful for other users that come across the same issue.
To update a workspace, you can use a request similar to the below:
curl --location --globoff --request PUT 'https://api.bitbucket.org/2.0/workspaces/WORKSPACE/pipelines-config/variables/{VARIABLE UUID}' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <TOKEN>' \ --data '{ "key": "TEST_VAR", "value": "TEST_VALUE2", "secured": false }'
This assumes you're using a workspace access token for authentication, that has at least the "Edit variables" scope.
Could you try making a request based on the example above and let us know how it goes?
Thank you, @Chris Fouts !
Patrik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The following options made it work.
--location --globoff
However, they're not mentioned here.
thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Chris Fouts ,
thanks for the update!
The --location option instructs curl to follow any redirects (it's not mandatory for this particular endpoint).
As for the --globoff, this is to make curl not to interpret special characters such as the curly brackets {} in the variable UUID.
If you don't provide this option, you would need to encode the curly brackets {} in the URL as follows :
{ |
%7B |
} |
%7D |
Example:
curl --request PUT 'https://api.bitbucket.org/2.0/workspaces/WORKSPACE/pipelines-config/variables/%7BVARIABLE UUID%7D' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <TOKEN>' \ --data '{ "key": "TEST_VAR", "value": "TEST_VALUE2", "secured": false }'
Thank you, @Chris Fouts !
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that makes sense. I'm embedding this in a script so I like the CLI options instead of the character replacement. Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.