Bitbucket CI CD Pipeline for Multiple Projects from One Repository

Author: Girada Mounika

This blog will help us understand how we can automate deployments using the bitbucket pipeline having multiple applications within a single repository.

Prerequisites
  1. Bitbucket Cloud account- User can create a new developer account from the link – https://bitbucket.org
  2. Anypoint platform account.

Aim:

  1. To deploy an application from bitbucket repository to Anypoint platform having multiple applications within the repo.
  2. When any application gets updated , the respective application gets deployed to the specified environment based on the branch.

Branching Strategy:

Below, the branching and repo strategy is followed for the POC that is being showcased.

  1. A single repository has three applications in it.
  2. There are two branches i.e Master branch and Develop branch.
  3. Whenever there are changes in code in single or multiple projects , automatic deployment takes place for updated code for all the projects in its respective environment i.e. Develop branch to Development and Master branch to UAT..

Steps:

  1. Firstly, a bitbucket account must be created and then go to the workspace and click settings. Open Workspace variables and set variables accordingly as per the below screenshot. These variables will be referred to the pipeline configuration file. Since these variables are set at the workspace level, they can be referred by all repositories and their pipelines
  1. Anypoint platform cloudhub environment client ID and client Secret can be pulled from Access Management. 

As shown in the below screenshot, refer to the Anypoint platform access management > environments for the client  ID and client Secret by clicking on the name of the environment. 

  1. As per the screenshot below, we have multiple applications within a single repo. We’ll be implementing CI/CD on each of these applications going forward.
  1. Create a branch “develop” from the master branch. This will ensure that we’re working on more than one branch to verify our pipeline conditions.
  1. Enable the bitbucket pipeline by navigating to repository > repository settings > pipelines > pipeline settings 
  1. For the deployment Settings navigate to Repository > Repository settings > Deployments and add Bitbucket environments as per the screenshot below. These environments will be referred to the pipeline configuration file and will be shown up in the Bitbucket pipeline dashboard accordingly.
  1. In the develop branch create the bitbucket-pipelines.yml file with the below code as shown in screenshot.This is the file which will have the configuration of the pipeline.
  1. Also, ensure that the pom.xml file of your mule applications has the below configuration for mule-maven-plugin.
  1. Now push the files from the develop branch to the master branch. For this create a pull request.
  1. The bitbucket-pipelines.yml code is now pushed to the master branch.
  1. Now we modify application 1 and application 3 in the develop branch and create the Pull request to merge it to the master branch.
  1. Upon merging the develop branch with the master branch,application 1 and application 3 gets automatically deployed to the UAT environment.
  1. In the anypoint platform’s runtime manager we can find the deployed applications.
  1. In order to deploy the modified multiple applications into the cloudhub , we need to create a pull request.
  1. Upon approval and merging the pull request to the master branch , all the modified applications get deployed.

Refer to the below screenshot for the pipeline.

  1. We can finally find the deployed applications in the run time manager.
  1. If we modify the applications in the master branch and push the modifications from master branch to develop branch , the applications get deployed to the development environment.
  1. Create a PR inorder to merge the changes to the develop branch from the master branch.

Refer to the below screenshot for the pipeline of applications deployment to cloudhub development environment.

  1. Finally we find the applications deployed to the development environment in the runtime manager.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.