I'm using yml anchors in my pipelines already and wanted to clean it up even more.
Right now I've an anchor step like that:
- step: &build-frontend
name: Build application and generate artifacts
- echo $DOTENV_STAGING | base64 --decode > .env
- yarn build
This step just builds my frontend code with a given .env file I have saved as base64 encoded string on my pipeline deployment variables.
The problem now is, I want to use the exact same step with a different variable on production as well, in that case it must be $DOTENV_PRODUCTION. How can I accomplish this somehow?
I know I could overwrite the whole step but then I also do not have to use the anchors. ;-)
What would also work is using the deployment name in an if condition but unfortunately it looks like there is no variable in the default variables where I can get it from?
I lost my mind for some reason and can't find any good solution.
Or maybe there is something more elegant?
Nice to hear from you!
@Ben as an alternative answer next to YAML anchors is to combine it with Merge Key Language-Independent Type for YAML™ Version 1.1 which allows to mix-in only the changing mapping with a base (definition).
Not so sure how well it works with arrays as it is about maps, here is an example which is working on Bitbucket Pipelines where I don't change a variable between two "same" steps, but the image name. That is linting the source-code with PHP 5.3 and then with PHP 7.4. Both steps are the same and only the image differs:
- step: &lint-php53
- step: &lint-php74
- step: *lint-php53
- step: *lint-php74
Note the `<<:` part. Ignore in this example it's not anchoring from `definitions`, it should be similarly possible, here in the example it's just all self-contained within the custom pipelines.
This is a real-life example, you can find the full file here: https://github.com/ktomk/pipelines/blob/master/bitbucket-pipelines.yml#L14-L40 (the highlighting will change over time and appear misplaced in the future).
You can set variables per deployment environments in Bitbucket Pipelines. This might do it already in your case.
You can also define variables so that they can only be used in a specific deployment environment.
You can manage deployment variables in Settings > Pipelines > Deployments.
Deployment variables override both team and repository variables, and are unique to each environment.
Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events