I am trying to reduce the amount of duplicated code in my .yml file. I've defined scripts at the top, then I try to reuse them in the different pipelines. I checked the syntax using the Bitbucket syntax validator and it was correct. The pipelines, however, do not build. I get the following error:
"There is an error in your bitbucket-pipelines.yml at
[pipelines > default > 0 > step > script].
To be precise: This section should be a list (it is currently defined as a map)."
Here's what I've been trying:
image: atlassian/default-image:2
options:
size: 2x
definitions:
scripts:
script_dependencies: &install_dependencies
- my steps
script_regular: &build_regular
- some more steps
script_release_candidate: &build_release_candidate
- some more steps
pipelines:
default:
- step:
script:
script_dependencies: *install_dependencies
script_regular: *build_regular
custom:
manual_run_release_candidate:
- step:
script:
script_dependencies: *install_dependencies
script_release_candidate: *build_release_candidate
Is there something wrong with this? Would appreciate some insight. Thank you.
Hi @Raiyan Ishmam,
As far as I know, the sections represented by anchors cannot be merged. They can be updated with <<: but not merged. It means that you can only reference one script section per step, not two of them in the same step/script.
You don't see any YML validation error due to the problem reported here:
I was checking a way to rewrite your script and this was my solution:
image: atlassian/default-image:2
options:
size: 2x
definitions:
script_dependencies: &install_dependencies
- echo "install_dependencies"
script_regular: &build_regular
- echo "build_regular"
script_release_candidate: &build_release_candidate
- echo "build_release_candidate"
pipelines:
default:
- step:
script: *install_dependencies
- step:
script: *build_regular
custom:
manual_run_release_candidate:
- step:
script: *install_dependencies
- step:
script: *build_release_candidate
I hope that helps.
Sorry for awakening this topic, but I have a similar issue but cannot use your suggested rewrite. My `*install_dependencies`-equivalent depends on deployment environment variables, which is only available in the last step. Any clean way around this?
It seems that the lack of merging lists in yaml and the lack of using environment variables outside of the deployment step, keeps getting in my way of defining a clean, easy to understand, build script. They end up having messy, duplicated sections due to these shortcomings. Which is unfortunate, because it seems like these capabilities shouldn't be too difficult to implement. :/
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.