I have defined multiple custom pipelines, and I want to reuse them in other custom pipeline.
The yaml file looks like this:
I want snapshot and restore custom pipelines run inside the deploy pipeline. I was searching a lot online. someone suggests me to use this format, others suggest me to use the yaml anchore. I have tried both, none of them works. I always got the configure error when I try to run it.
the error looks like this
There is an error in your bitbucket-pipelines.yml at [pipelines > custom > deployStagingNew > 2 > step]. To be precise: This section should be a map (it is currently defined as a list).
One thing I haven't tried, which is to use definitions. However, I don't want to add extra codes. I really appreciate any inputs.
Hello @Ming_Huang,
There's no way to call a pipeline from another pipeline, but you can indeed make use of anchors. Note that anchors are language-level entities, so what you need is a valid configuration file after all aliases to anchors are resolved (content inlined).
I'd put anchors on steps of each custom pipeline (looks like there's just one in each) and then reuse them like you tried in your example. E.g. the anchor should be on a step of a custom pipeline, not on the pipeline itself.
Hope this helps.
Cheers,
Daniil
Hi Daniil, as you said that there is no way to call a pipeline from another pipeline. and the anchor should not be on the pipeline itself, what do you mean by that? Also, could you give me an example in my case? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Based on the understanding of your suggestion, is this what you refer?
this is still calling pipelines from other pipeline, right? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's an example of reusing steps: https://bitbucket.org/atlassianlabs/intellij-bitbucket-references-plugin/src/master/bitbucket-pipelines.yml
In that particular example the reused steps are defined in definitions section, but in fact you don't have to keep them there. YAML aliases are resolved to the closest anchor, so you can just put anchors on steps in one of the pipelines and then reuse them in other pipelines.
Does this make sense?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I dont really want to use definitions in my case. I want to put anchor on each step of custom pipelines, which will be referred later.
In the calling custom pipeline, do I need to use
- <<: *snapshotDatabasets
or
- step: *snapshotDatasets
? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I dont really want to use definitions in my case. I want to put anchor on each step of custom pipelines, which will be referred later.
Yes, you can definitely do that – just as you did in the excerpts you posted above.
One note about your last screenshot though: it doesn't seem to be valid YAML as *image alias can't be resolved (there's no anchor earlier in the file).
this is still calling pipelines from other pipeline, right? Thanks
Not really, you're reusing some bits using YAML anchors/aliases. When it is "compiled", all aliases are simply inlined, so from Pipelines' perspective all pipeline definitions are completely independent.
In the calling custom pipeline, do I need to use
- <<: *snapshotDatabasetsor
- step: *snapshotDatasets
Assuming the anchor was on the step, like on the last screenshot, the second option is correct. The first one with some modification can be used to make new step override something from the anchored one. Here's an example:
- step: &reuseMe
name: I am step to be reused
image: example:1
- step: *reuseMe
- step:
<<: *reuseMe
name: I am reusing step above but override name
This is equal to this YML:
- step:
name: I am step to be reused
image: example:1
- step:
name: I am step to be reused
image: example:1
- step:
name: I am reusing step above but override name
image: example:1
Again, this is just YML syntax, not specific to Pipelines configuration.
Hope this helps.
Cheers,
Daniil
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.