You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
So I've been creating an automated pipeline and require the ability to change environmental variables in bitbucket pipelines programatically, I have looked at the various pieces of documentation for this and can't make heads or tails of how to actually go about this, I would consider this to be a fairly reasonable use case, I'm not building an application on top of the API, I just want to POST new variables to my pipeline, can you please give me a detailed guide on how to do this, I've been looking through this stuff for days now and have made barely any progress.
If you want to create new variables, you can use the API POST call
An example payload
{
key: "foo",
value: "bar",
secured: false
}
If you want to change an existing environment variable you can use the API PUT call on a specific variable uuid (this does require you to know the variable uuid) you want to update
An example payload
{
key: "foo",
value: "baz",
}
If you need to set up authentication to make these calls, you can follow the guide here https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication
Hope this helps!
Davina
Hey @davina,
I am trying to update pipeline environment variables via the API PUT schema you have specified above and am getting a 400 - Bad Request error. I am making the request with Python as follows:
url = 'https://api.bitbucket.org/2.0/repositories/{username}/{repo_slug}/pipelines_config/variables/{variable_uuid}'
headers = {'Content-Type': 'application/json'}
payload = {
"key": {environment_variable_name},
"value": {updated_value}
}
r = requests.put(url, json=payload, auth=('{USERNAME}', '{PASSWORD}'), headers=headers)
I have previously gotten the variable_uuid via the API. It seems like it does not like the payload I am providing. I have also tried including "uuid": {variable_uuid} and "secured": {boolean} as part of the payload for completeness sake according to the docs stated above. I have also ensured that the environment variable exists prior to update.
Any insight would be much appreciated, thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmmm that is strange, what you've written looks correct. Is there any other information in the error? for example if your json is malformed you will get a 400 Bad Request with
{
"error": {
"message": "An error occurred parsing the JSON.",
"data": {
"key": "rest-service.request.invalid-json"
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wish there was, here is the entire response I receive:
{
"error": {
"message": "Bad request",
"data": {
"arguments": {
"spanId": "d3759f902c1d0268",
"parentSpanId": "c58f6fef99732713",
"traceId": "c58f6fef99732713"
},
"key": "Bad Request"
},
"detail": "HTTP 400 Bad Request"
}
}
Thanks again for your help on this!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
any news here? I have the same problem:
curl -X PUT \
https://api.bitbucket.org/2.0/repositories/XX/YY/pipelines_config/variables/UID \
-H 'Authorization: Basic %code%' \
-H 'Content-Type: application/json' \
-d '{
"value": "xxx",
"key": "%NAME%"
}'
response:
{
"error": {
"message": "Bad request",
"data": {
"arguments": {
"spanId": "49a845225e3881ad",
"parentSpanId": "28aa2925157e7c3f",
"traceId": "28aa2925157e7c3f"
},
"key": "Bad Request"
},
"detail": "HTTP 400 Bad Request"
}
}
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.
This is the worst API I've ever used and oh boy have I used some bad ones.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Announced in this blog, this holiday season we’re celebrating all things CI/CD and between now and the end of 2019 we’ll be showcasing content, use cases, feature announcements and more. One featur...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.