Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,457,006
Community Members
 
Community Events
176
Community Groups

Is there a way to set a secret variable for pipeline via curl from outside without UI?

I have a lot of lookups in my Ansible playbook. This works like a charm on a shell script form my local computer but inside a bitbucket pipeline I have not the rights to access aws secret manager so the idea was to put all lookups in a local script and set it via curl command in the bitbucket pipeline as new variables. So bitbucket pipelines use only secret variables to run with Ansible. If there are changes in the variables I can set it from outside without click through the error-prone process to set the variables new. We talk about over 50 variables which will change regulary.

Is there a simple way with curl to set such pipeline variables?

 

1 answer

1 accepted

0 votes
Answer accepted

Hi @Lars_langhans,

There are API endpoints that you can use to either create a new variable or update the value of an existing variable (also secured ones).

If these are Repository variables, the endpoints are the following:


An example with curl for each of the endpoints:

curl -u BitbucketUsername:AppPassword -X POST https://api.bitbucket.org/2.0/repositories/WORKSPACE-ID/REPO-SLUG/pipelines_config/variables/ --header 'Accept: application/json' --header 'Content-Type: application/json' --data '{"key": "mySecuredVariable", "value": "123456","secured": true}'
curl -u BitbucketUsername:AppPassword -X PUT https://api.bitbucket.org/2.0/repositories/WORKSPACE-ID/REPO-SLUG/pipelines_config/variables/%7BVARIABLE-UUID%7D --header 'Accept: application/json' --header 'Content-Type: application/json' --data '{"value": "987654"}'

For the second example with curl (updating an existing variable's value), you will need to specify the variable UUID in the API URL. You can use the following endpoint to get all variables and find the UUID of the one you want to update

https://api.bitbucket.org/2.0/repositories/WORKSPACE-ID/REPO-SLUG/pipelines_config/variables

 

If you are using workspace variables, the endpoints are the following:

 

If you are using deployment variables, the endpoints are the following:

If you have any questions, please feel free to let me know!

Kind regards,
Theodora

Hi,

thank you very much. Create a new variable works like a charm. List variables works also.

After some work I decided myself to use deployment environments instead of normal variables. For this I need a environment_uuid and within the UI I can't see this uuid.

Maybe within the API:

I found "List environments"

And this offers me the environment_uuid.

To list all environment uuids in a simple online list.

AUTHENTICATION=<username>:<app password>
curl -u ${AUTHENTICATION} --request GET \
--url "https://api.bitbucket.org/2.0/repositories/${WORKSPACE_ID}/${REPO_SLUG}/environments/" \
--header 'Accept: application/json' | jq '.values[] | "\(.category.name)=\(.uuid)"'
Like Theodora Boudale likes this

Hi Lars,

Thank you for the updates and you are very welcome.

You are also right about the API for listing the environments, the endpoint is this one

https://developer.atlassian.com/cloud/bitbucket/rest/api-group-deployments/#api-repositories-workspace-repo-slug-environments-get

If you need anything further, please feel free to reach out!

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events