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

How to pass variables in bitbucket pipelines

sschroders May 15, 2024

I am building a pipeline to deploy my .net projects. in my solution I have several azure functions all under same repo. I want to zip and deploy them. I want to reuse my zip script and therefore I have put it in a step. however  to path to which files it needs to zip is different per function (.net code). how can i use variables to set the path as part of my pipeline step?

1 answer

1 vote
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2024

Bitbucket has dedicated support for repository (and even workspace!) variables.

See: https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/

sschroders May 16, 2024

@Aron Gombas _Midori_ thanks for your help I have seen this page but I still don't see how I can define and use the variables in the ymal? I need to overwrite the value of the variable in different steps. but everything I have tried my variable's value is not changed. any idea how can i do this. perhaps an example. I really appreciate this 

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 22, 2024

Hi @sschroders,

If you have a Repository, Workspace, or Deployment variable named MyVar, you can reference it in the bitbucket-pipelines.yml file as $MyVar (except if you use a Widnows self-hosted runner for your Pipelines builds, in which case you will need to reference it as $env:MyVar).

For example, the following pipeline will print the value of the variable named MyVar:

image: atlassian/default-image:4

pipelines:
default:
- step:
name: 'First Step'
script:
- echo $MyVar

If you want to change the value of the variable in a second step, you can do it as follows:

image: atlassian/default-image:4

pipelines:
default:
- step:
name: 'First step'
script:
- echo $MyVar
- step:
name: 'Second step'
script:
- MyVar="some other value"
- echo $MyVar

Please keep in mind that this will change the value of the variable only in this second step. If you have a third step, it will read the value of the variable from Repository, Workspace, or Deployment variables, so it will have the original value.

If the different steps that use this variable are deployment steps (with the use of the deployment keyword), you can then create a variable named MyVar in every deployment environment that uses it and give it a different value for each environment (no need to change the value in the yml file).

Please feel free to reach out if you have any questions!

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events