You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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 .
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.