How can I use deployments with shared pipeline and use deployment with importing particular steps
Asked by Hareesh Kanchala:

I have a shared pipeline created for all my microservices, the steps are more or less same but vary on branch execution. with different variable set. How can I achieve below functionality  

Example:

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Shared Pipeline

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
export: true

definitions:  
pipelines:  
share-pipeline-java8: \&share-pipeline-java8  
- step: \&Maven-Build-and-Test  
image:  
name: abc.io/maven:3.9-jdk8  
username: $ART_USER  
password: $ARTI_PASSWORD  
caches:  
- maven  
script:  
- mvn clean install  
artifacts:  
- target/\*.jar  
after-script:  
# Collect checkstyle results, if any, and convert to Bitbucket Code Insights.  
- pipe: atlassian/checkstyle-report:0.3.0

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Import Pipeline

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
pipelines:  
branches:

develop:  
import: xyz:develop:share-pipeline-java8  
deployment: develop  
step: \*Maven-Build-and-Test

master:  
import: xyz:master:share-pipeline-java8  
deployment: production  
step: \*Maven-Build-and-Test


Answers:
author: Caterina Curti
body: Hi [@Hareesh Kanchala](/t5/user/viewprofilepage/user-id/5374621),

Now that [Dynamic Pipelines](https://bitbucket.org/blog/introducing-dynamic-pipelines-a-new-standard-in-ci-cd-flexibility) have been released, you can achieve a greater level of flexibility with the Bitbucket pipelines.

Last week, I published this article explaining how to add a step dynamically to a repository. This approach offers a greater level of flexibility, considering that the app logic can change the entire pipeline of a repository.  

<br />

Hope this will help managing pipelines,  
Caterina


author: Theodora Boudale
body: Hi Hareesh and welcome to the community!

I'm afraid that it is not possible to share only certain steps at the moment or customize elements like deployments.

We have a feature request for the ability to share certain steps of a pipeline:

* <https://jira.atlassian.com/browse/BCLOUD-22855>

You can add your vote and feedback to that ticket to express your interest.

In the meantime, you can achieve what you want by creating a separate pipeline for each combination of pipeline step and deployment environment in the shared pipeline, and then use them in the imported repo.

We have the following documentation on sharing pipelines configuration that also includes many frequently asked questions:

* <https://support.atlassian.com/bitbucket-cloud/docs/share-pipelines-configurations/>

Please feel free to reach out if you have any other questions!

Kind regards,  
Theodora

comments: author: Hareesh Kanchala
body: Hi Theodora, Thanks for getting back. In that case Can we do the same for import pipelines with a deployment in that case?  

pipelines:  
branches:  
hareesh/multi_branch_shared_pipeline:  
deployment: Develop  
import: abc:hareesh/xyz:share-pipeline


author: Theodora Boudale
body: Hi Hareesh,

A deployment is a property of a step or a stage and not of the whole pipeline. I'm afraid that you cannot use a definition like the one you shared. You will need to define the deployment in the Shared Pipeline repo, in the specific step that uses a deployment, as follows:

```
export: true

definitions:
  pipelines:
    share-pipeline-java8-production:
      - step: &Maven-Build-and-Test
          deployment: develop
          image:
            name: abc.io/maven:3.9-jdk8
            username: $ART_USER
            password: $ARTI_PASSWORD
          caches:
            - maven
          script:
            - mvn clean install
          artifacts:
            - target/*.jar
          after-script:
            # Collect checkstyle results, if any, and convert to Bitbucket Code Insights.
            - pipe: atlassian/checkstyle-report:0.3.0
```

If you have more than one deployment environment that you want to use this way, you will need to add separate definitions for the same step with a different deployment environment.

Please feel free to let me know if you have any questions.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud