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!
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 :
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.