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,456,925
Community Members
 
Community Events
176
Community Groups

Is there a way to have local variables for bitbucket pipelines within a step?

I'm wondering if there is a way to do:

```yaml

definitions:
  scripts:
    - script: &echo_script
        - echo ${MESSAGE}
pipelines:
  default:
    - step: &my_step1
          name: Test1
          local_variables:
            - MESSAGE="I want my bitbucket-pipelines.yaml to Don't-Repeat-Yourself (DRY)"
          script:
             <<: *echo_script
    - step: &my_step2
          name: Test2
          local_variables:
            - MESSAGE="This would allow me to do this"
          script:
             <<: *echo_script
```

Expected output for a run is:
```
Test1 : "I want my bitbucket-pipelines.yaml to Don't-Repeat-Yourself (DRY)"
Test2 : "This would allow me to do this"
```
Thanks

1 answer

0 votes
Patrik S Atlassian Team Jul 19, 2022

Hello @Paul Helter ,

Thank you for reaching out to Atlassian Community!

I'm afraid that at this moment it's not possible to define environment variables at step level. We already have a feature request to implement that functionality, though : 

I would suggest you to add your vote there, since this helps both developers and product managers to understand the interest. Also, make sure you add yourself as a watcher in case you want to receive first-hand updates from that ticket. Please note that all features are implemented with this policy in mind.

While this feature is not implemented, a workaround-ishy way of having different values for the same variable is to define different deployment environments , create the deployment variables in each deployment environment, and then assign a different deployment to each step, like the below example : 

pipelines:

  default:

    - step:

          name: Deploy to Test

          deployment: env1

          script:

             - echo $DEPLOYMENT_VARIABLE

    - step:

          name: Deploy to Test

          deployment: env2

          script:

             - echo $DEPLOYMENT_VARIABLE

So, although the environment variable name is the same, you can set different values to it for each deployment environment.

Hope that helps! Let me know if you have any questions.

Thank you, @Paul Helter .

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events