Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Reuse other custom pipelines in one custom pipeline

Ming_Huang February 13, 2020

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
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2020

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

Ming_Huang February 13, 2020

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 

Ming_Huang February 13, 2020

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

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2020

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?

Ming_Huang February 13, 2020

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

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 14, 2020

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
AUG Leaders

Atlassian Community Events