This image is what I want to do in the api.
I want to add a variable to an already existent environment on a repository using the api. This is not a repository "global" variable. This is a specific environment variable.(On this environment I am using staging)
From the documentation I found this url that should do the trick, but I have no idea how to use it to achieve what I want.
/2.0/repositories/{workspace}/{repo_slug}/environments/{environment_uuid}/changes/
Hello,
We've added endpoints for interacting with deployment variables to our public API.
You can find the documentation for them here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/deployments_config/environments/%7Benvironment_uuid%7D/variables
Thanks,
Phil
Hi @Marcelo_Anabuki,
You can add Deployment Variables through API as follows with an OAuth2 access token.
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {access_token}" \
-d '{"key": "key", "value": "value", "secured": false }' \
https://api.bitbucket.org/internal/repositories/{repo_slug}/deployments_config/environments/{environment_uuid}/variables/
This is internal API and thus not documented, out of curiosity what is the use case for adding variables this way over the UI?
Thanks,
Peter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Peter Plewa ,
Thanks for the help. I will try it out.
Our use case is that we are automating a few repository configurations.
We are using bitbucket pipelines and we need to set some secrets to make our deploy work, adding/updating it manually takes a lot of time and is prone to error.
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.
409 can happen if you are trying to submit the same variable name to the same environment, which needs to be unique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would very much like to see this in v2.
Our different environments deploy to different hosts. We have been manually configuring this with key-value pairs in the environment variables.
We use the v2 API to instantiate new repositories, set up the branches, the branch permissions, turn on pipelines etc - so being able to set the environment variables would be useful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
These endpoints have been added to the V2 API: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/deployments_config/environments/%7Benvironment_uuid%7D/variables
As our internal APIs do not have a deprecation policy. I suggest you migrate to the 2.0 API as soon as you're able, so you don't run into any issues in the future.
Thanks,
Phil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've been working on a PowerShell module to front the Bitbucket API for automation. I've added cmdlets for working with the deployment variables in the latest version.
https://www.powershellgallery.com/packages/Atlassian.Bitbucket/0.15.1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter Plewa , I'm trying to do the same thing as Marcelo, but am unable to get this working.
I keep getting a Resource not found error, and the detail is "There is no API hosted at this URL.\n\nFor information about our API's, please refer to the documentation at: https://developer.atlassian.com/bitbucket/api/2/reference/".
I'm trying to hit this through Postman, but curl isn't working for me either. Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Allen,
Send us the curl command line that you are using.
I spent some time trying to make it work so I can probably figure it out if I see the command.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Marcelo,
It looks pretty much exactly like what Peter had, I've changed the data in here (for obvious reasons) but this is effectively what the command looks like:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer REDACTED" \
-d '{"key": "test", "value": "value", "secured": false }' \
https://api.bitbucket.org/internal/repositories/my-service/deployments_config/environments/{123456g8-99k5-j98k-82h4-b6fb67e9eeb1/variables/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[deleted] - It looks like you are missing the team portion from the path before the repo name...
You can also use my PowerShell module which I've added support for variables.
https://www.powershellgallery.com/packages/Atlassian.Bitbucket/0.15.1
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.