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,646,746
Community Members
 
Community Events
196
Community Groups

Can a default variable be used as repository user variable?

Edited

Hello,

 the idea is to define an IMAGE repository variable as a combination of default variables so that all steps in a pipeline can refer to it without redefining:

on the repo level in the "REpository variables":

IMAGE -

$BITBUCKET_REPO_SLUG_$BITBUCKET_BRANCH

 

in the pipeline:

steps:
- step: &Build_And_Scan
name: Build & Run Static Security Code Dependency Test
script:
- echo $IMAGE
- export DOCKER_FILE="dockerfile"
- docker builder build -t $IMAGE -f $DOCKER_FILE .

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Nov 02, 2022

Hi @AZZ,

I'm afraid that it is not possible to use the value of default variables when defining a repository variable. We have a feature request about this in our issue tracker:

I would suggest adding your vote to it (by selecting the Vote for this issue link) and leaving a comment to express your interest. You can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates.

In the meantime, a way to work around this issue would be by defining the variable in the script of the steps that are using it. For example, in the step you posted here you can do the following:

steps:
- step: &Build_And_Scan
name: Build & Run Static Security Code Dependency Test
script:
- IMAGE=${BITBUCKET_REPO_SLUG}_${BITBUCKET_BRANCH}
- echo $IMAGE
- export DOCKER_FILE="dockerfile"
- docker builder build -t $IMAGE -f $DOCKER_FILE .

Please keep in mind that $BITBUCKET_BRANCH is only available on branches, it is not available for builds against tags, or custom pipelines.

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

Kind regards,
Theodora

@Theodora Boudale,

 thank you for the answer. I added my voice to the ticket.

 

In the above situation - is there a way to avoid defining the same variable for each step?

The end goal is to do this - https://community.atlassian.com/t5/Bitbucket-questions/Pipelines-Image-name-as-an-artifact/qaq-p/2179719

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Nov 04, 2022

You are very welcome @AZZ.

If you want to pass the value of the variable, this is possible by adding some additional commands in your bitbucket-pipelines.yml file that write the value to a file, pass the file as an artifact, and then source the file in subsequent steps.

Please see an example below:

pipelines:
default:
- step:
script:
- IMAGE=${BITBUCKET_REPO_SLUG}_${BITBUCKET_BRANCH}
- echo export IMAGE=${BITBUCKET_REPO_SLUG}_${BITBUCKET_BRANCH} >> build.env
- echo $IMAGE
artifacts:
- build.env
- step:
script:
- source build.env
- echo $IMAGE

Please feel free to let me know if that works for you and if you have any questions.

Kind regards,
Theodora

Suggest an answer

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

Atlassian Community Events