Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Updating repository variables via pipeline

Meagan November 14, 2023

Problem: we want to update our version number in the pipeline when it runs successfully. We currently pull the version number from the repo's env variables and after a build it should change the variable .

So I was looking at the api and have this:

 

curl --request PUT \
--url 'https://api.bitbucket.org/2.0/repositories/{wksp}/{repo}/pipelines_config/variables/{uuid}' \
--user 'user:pwd' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"type": "pipeline_variable",
"uuid": "{uuid}",
"key": "VERSION",
"value": "0.0.0-TEST"
}'

However I get a

{"error": {"message": "Bad request", "detail": "Unexpected response body", "data": {"key": "unexpected.response.body", "arguments": {}}}}

I have tried multiple configurations. This is straight from the API docs.

Note that getting the variable works. And I have matched the fields from that.

Thank you!

 

 

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 16, 2023

Hello @Meagan Hiatt 

and thanks for reaching out to Community!

The update an environment variable API endpoints expect the variable_uuid in the URL path, and since this UUID contains curly braces, the value in the URL must be URL-encoded.

I was able to reproduce the same error you were receiving when I tried to provide the UUID unencoded in the format {12345678-abcd-1234-abcd-1234abcd1234}.

The encoding values (see URL encoding reference) of curly braces are as follows  : 

  • {   -  %7B
  • }   -  %7D

And the encoded URL will look like the below : 

https://api.bitbucket.org/2.0/repositories/WORKSPACE/REPOSITORY/pipelines_config/variables/%7B12345678-abcd-1234-abcd-1234abcd1234%7D

With %7B and %7D added to the beginning and end of the variable UUID, respectively.

Example curl request : 

curl --request PUT -u 'USERNAME:APP_PASSWORD' 'https://api.bitbucket.org/2.0/repositories/WORKSPACE/REPOSITORY/pipelines_config/variables/%7B12345678-abcd-1234-abcd-1234abcd1234%7D' --header 'Content-Type: application/json' --header 'Accept: application/json' --data '{

"type": "pipeline_variable",

"uuid": "{12345678-abcd-1234-abcd-1234abcd1234}",

"key": "MY_VAR",

"value": "123"

}'

Hope that helps! Should you have any questions or run into any issues trying the suggestion above, feel free to ask :) 

Thank you, @Meagan Hiatt !

Patrik S 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events