How to integrate pipes into a custom/parent pipe?
Asked by Micha Mail?nder:

Hello,

we have a lot of microservice repositories. And we want to write a parent CI/CD pipe that we can reuse in any of these repositories to reduce the management effort if we have to adjust the CI/CD pipe.

Based on the doc of writing a custom pipe (<https://support.atlassian.com/bitbucket-cloud/docs/write-a-pipe-for-bitbucket-pipelines/>) I'm understanding that I have to write shell or python scripts. But my use case is mostly writing a parent pipe that is including other pipes e.g. the sonarcloud pipe. And this standard pipe I can reuse in all my repositories.

So my question is: How am I able to integrate other pipes into my parent pipe?


Answers:
author: Igor Stoyanov
body: Hi [@Micha Mail?nder](/t5/user/viewprofilepage/user-id/3886582) . Thanks for you question. It's a good case to use [trigger-pipeline pipe](https://bitbucket.org/atlassian/trigger-pipeline/src/master/).  
All you need is to use this pipe, pass credentials and specify the name of your repo. Example below:

```
script:  - pipe: atlassian/trigger-pipeline:4.2.1    variables:      BITBUCKET_USERNAME: $BITBUCKET_USERNAME      BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD      REPOSITORY: 'your-awesome-repo'
```

<br />

Regards, Igor.

comments: author: Micha Mail?nder
body: Thanks for the reply [@Igor Stoyanov](/t5/user/viewprofilepage/user-id/4550492)

But can I use that also that the triggered pipeline uses my current repository code as the base?  

My understanding:

One repo = One pipe

If I run the pipe_1.yml that is included in repo_1 then it uses the data from repo_1. If I trigger pipe_2 (with the trigger-pipeline) of repo_2 then the pipe_2 uses the code of repo_2 and not from repo_1. Or do I misunderstand here something, and I can use pipe_2 to run it with the code of repo_1?


author: Igor Stoyanov
body: [@Micha Mail?nder](/t5/user/viewprofilepage/user-id/3886582) As far as i understand, you can set

```
REPOSITORY: 'your-awesome-repo'
```

with repo_1 or repo_2 in any repository where you want to trigger your pipeline.  

Example: in repository repo_1 in pipe_1.yml you can set

```
REPOSITORY: 'repo_2'
```

This is your case?  

Regards, Igor.


author: Micha Mail?nder
body: Not sure if we're talking from the same :D  

I try to explain it with the picture:

![Pipeline.png](https://community.atlassian.com/t5/image/serverpage/image-id/161040i9C37161F1CB4AC01/image-size/large?v=v2&px=999 "Pipeline.png")

If I'm understanding you correctly, I can use the "trigger-pipeline" to call another pipeline.

1. So I'm including in the bitbucket-pipelines.yml of Repository 1 only the trigger-pipeline. With the trigger-pipeline, I call Repository-2.
2. The Repository-2 bitbucket-pipelines.yml is including the CI/CD pipeline script that I really want to run in Repository-1.

My understanding is, the Repository-2 bitbucket-pipeline.yml would use now the code that is inside Repository-2. But instead, it should use the code of Repository-1.

So what do I have to do for that, that the Repository-2 bitbucket-pipelines.yml is used to run on the code of repository-1?

Hoping that this explanation is now more clear ;)


author: Igor Stoyanov
body: > My understanding is, the Repository-2 bitbucket-pipeline.yml would use now the code that is inside Repository-2. But instead, it should use the code of Repository-1. So what do I have to do for that, that the Repository-2 bitbucket-pipelines.yml is used to run on the code of repository-1?

[@Micha Mail?nder](/t5/user/viewprofilepage/user-id/3886582) If you want to use code of Repository-1 inside bitbucket-pipeline.yml of Repository-2 you need to add this to bitbucket-pipeline.yml of Repository-2:  

```
script:  - pipe: atlassian/trigger-pipeline:4.2.1    variables:      BITBUCKET_USERNAME: $BITBUCKET_USERNAME      BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD      REPOSITORY: 'Repository-1'
```

without any changes in bitbucket-pipeline.yml of Repository-1  

Regards, Igor.


Tags: bitbucket-pipelines

bitbucket-cloud

cloud