Bitbucket CI/CD pipeline for multiple projects from one repository
- November 25, 2021
This tech article will help you understand how to automate deployments using the Bitbucket pipeline when you have multiple applications within a single repository.
Prerequisites
- Bitbucket cloud account — you can create a new developer account at https://bitbucket.org
- Anypoint Platform account
Goals
- To deploy an application from a Bitbucket repository to the Anypoint Platform when multiple applications are within the repository
- When any application gets updated, the respective application gets deployed to the specified environment based on the branch
Branching strategy
The point of contact showcased here uses the following branching and repo strategy.
- A single repository has three applications in it.
- There are two branches i.e Master branch and Develop branch.
- 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
- Create a Bitbucket account
- Go to the Workspace and click Settings
- Open Workspace variables and set Variables based on your needs These variables will be referred to the pipeline configuration file. Because these variables are set at the workspace level, they can be referred by all repositories and their pipelines
- Go to Access Management and retrieve the Anypoint Platform and CloudHub environment client ID and client secret (click on the name of the environment)
- From the master branch, create a branch “develop” — this will ensure that we’re working on more than one branch to verify our pipeline conditions
- Enable the Bitbucket pipeline by navigating to repository -> repository settings -> pipelines -> pipeline settings
- For the deployment settings, navigate to repository > repository settings > deployments and add Bitbucket environments — these environments will be referred to the pipeline configuration file and will be show up in the Bitbucket pipeline dashboard
- In the Develop branch, create the bitbucket-pipelines.yml file, which will have the configuration of the pipeline
- Push the files from the develop branch to the master branch — to do this, create a pull request; the bitbucket-pipelines.yml code is now pushed to the master branch
- Modify application 1 and application 3 in the develop branch and create the Pull request to merge it into the master branch
Also, ensure that the pom.xml file of your Mule application has the correct configuration for the mule-maven-plugin
Upon merging the develop branch with the master branch, application 1 and application 3 will be automatically deployed to the UAT environment.
In the Anypoint Platform’s Runtime Manager, you’ll find the deployed applications.
- To deploy the modified multiple applications into CloudHub, you need to create a pull request
- Upon approval and merging the pull request into the master branch, all modified applications will be deployed
Deployed applications can be found in the Runtime Manager.
If you modify the applications in the master branch and push the modifications from master branch to develop branch, the applications will be deployed to the development environment.
- Create a pull request to merge the changes to the develop branch from the master branch.
Applications deployed to the development environment can be found in the runtime manager.
— By Girada Mounika