It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Reuse other custom pipelines in one custom pipeline

I have defined multiple custom pipelines, and I want to reuse them in other custom pipeline.

The yaml file looks like this:
Screen Shot 2020-02-13 at 1.34.24 PM.png

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. 

1 answer

0 votes

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 

Based on the understanding of your suggestion, is this what you refer? 

Screen Shot 2020-02-13 at 5.00.23 PM.png

 

this is still calling pipelines from other pipeline, right? Thanks

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?

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

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 

- <<: *snapshotDatabasets

or 

- 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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Bitbucket Server 7.0 is here!

Hello Community, I’m Anton Genkin, a product manager on the Bitbucket Server and Data Center team and am excited to share that Bitbucket Server 7.0 is now available! It's a platform release, one th...

370 views 6 2
Read article

Community Events

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

Events near you