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.
- Bitbucket Cloud account- User can create a new developer account from the link – https://bitbucket.org
- Anypoint platform account.
- To deploy an application from bitbucket repository to Anypoint platform having multiple applications within the repo.
- When any application gets updated , the respective application gets deployed to the specified environment based on the branch.
Below, the branching and repo strategy is followed for the POC that is being showcased.
- 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..
- 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
- 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.
- 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.
- 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.
- 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 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.
- 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.
- Also, ensure that the pom.xml file of your mule applications has the below configuration for mule-maven-plugin.
- Now push the files from the develop branch to the master branch. For this create a pull request.
- The bitbucket-pipelines.yml code is now pushed to the master branch.
- Now we modify application 1 and application 3 in the develop branch and create the Pull request to merge it to the master branch.
- Upon merging the develop branch with the master branch,application 1 and application 3 gets automatically deployed to the UAT environment.
- In the anypoint platform’s runtime manager we can find the deployed applications.
- In order to deploy the modified multiple applications into the cloudhub , we need to create a pull request.
- 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.
- We can finally find the deployed applications in the run time manager.
- 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.
- 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.
- Finally we find the applications deployed to the development environment in the runtime manager.