CI/CD Using Maven With Connected Applications in Anypoint Platform for Runtime Fabric
Define the essential arrangements and actions to practice Connected Apps instead of the common User/Password (Anypoint credential) in a CICD pipeline.
Join the DZone community and get the full member experience.
Join For FreeObjective
The objective of this article is to define the essential arrangements and actions to practice Connected Apps instead of the common User/Password (Anypoint credential) in a CICD pipeline.
Connected Apps help users authorize their access without sharing sensitive credentials or giving full authority of their accounts to third people and Users can also withdraw introduction to them at any time. These Apps will use a Client ID and Secret that will allow them to do some actions, for instance, deploy, publish assets to Exchange, apply/promote policies, etc. But they will not be able to login into the platform.
Prerequisites
- Access to BitBucket Server and project repo configured in BitBucket tool.
- Bamboo should have access to MuleSoft Platform APIs.
- Maven version 3.x.x installed and configured in Bamboo (alternative is to use maven wrapper)
- Create Connected APP and copy client_id and secret to be configured maven CICD process which is associated with the Bamboo tool.
CI/CD Process
To follow the below approach, the user has to design API in the Design center then to publish in exchange. Once it is published in exchange, the developer imports API from Design Center in Anypoint studio to implement business logic and commit code to BitBucket repository.
Once code is committed in the BitBucket repository, the CICD process will execute and operate with the sequence as defined in the below pic...
As API is designed and published in exchange and customized code has been committed in the repository. Now, we need to configure the plan and deployment environment in Bamboo once associated with the BitBucket repository.
Below steps for Bamboo tool to perform steps #4,#5, #6,#7 and #8.
Configure Build Step as Below
Configure Deployment Environment and associate with plan as above...
Initiate Deployment Environment Configuration
Configure steps in Task [SandBox]
Command Configured in Task
Task - Script for login (To get token using connected app credentials.)
x
echo $'\n' >> anypointrtf-repo/src/main/resources/config-${bamboo.dev.sdlc.env}.properties
echo 'token='$(curl -s "https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token" -X POST -H "Content-Type: application/json" -d '{"grant_type": "client_credentials", "client_id": ${bamboo.app.client.id}, "client_secret":${bamboo.app.client.secret}}' | sed -n 's|.*"access_token":"\([^"]*\)".*|\1|p') >> anypointrtf-repo/src/main/resources/config-${bamboo.dev.sdlc.env}.properties
Create API Instance
xxxxxxxxxx
clean package -Papi -Dtoken=${bamboo.inject.token} -DorgId=${bamboo.orgId} -Dversion=${bamboo.inject.apiVersion} -DenvId=${bamboo.dev.sdlc.env} -DassetId=${bamboo.inject.assetId} -DassetVersion=${bamboo.inject.assetVersion} -Dpolicy=${bamboo.inject.policy} -DapiImplUri=${bamboo.inject.implUri} -DapiProxyUri=${bamboo.inject.proxyUri} -DapiType=${bamboo.inject.apiType} -DdeploymentType=RF -DapiInstanceLabel=${bamboo.inject.apiInstanceLabel} -Dpackaging=pom -DbasicSlaMaxReq=${bamboo.inject.basicSlaMaxReq} -DgoldSlaMaxReq=${bamboo.inject.goldSlaMaxReq} -DplatinumSlaMaxReq=${bamboo.inject.platinumSlaMaxReq} -DnewVersion=1.0.${bamboo.buildNumber}
Install and Deploy Application
xxxxxxxxxx
deploy -Pdeploy -DmuleDeploy -DnewVersion=1.0.${bamboo.buildNumber} -DclientId=${bamboo.client.id.dev} -Dsecret=${bamboo.client.secret.dev} -Dcpu=${bamboo.inject.cpu} -Dmemory=${bamboo.inject.memory} -DreplicationFactor=${bamboo.inject.replicationFactor} -DclusteringEnabled=${bamboo.inject.clusteringEnabled} -Dartifact.env=${bamboo.artifact.sdlc.env} -DrtfName=${bamboo.inject.rtfName} -Dprovider=${bamboo.rtf.provider.dev} -Dtoken=${bamboo.inject.token} -Denv=${bamboo.sdlc.sandbox} -DapiId=${bamboo.inject.api.id} -Dpackaging=mule-application
Once the above steps are done, the configuration is done. Start plan execution to publish the application to exchange which is required for Runtime Fabric application.
Once the plan executed is successful, you will able to see green status of build-in bamboo.
Now, MuleSoft application artifacts will be published to exchange.
Now in the final stage of deployment in the configured environment. Execute the process manually or self trigger.
Once Deploy profile executed with success, we will able see in API manager and Runtime Manager that application is deployed and API status changed to activated state.
API Manager (API Status changed to Active)
Runtime Manager (Application status will be in Running state)
BitBucket Bambo CICI RTF Connected app
Thanks.
Opinions expressed by DZone contributors are their own.
Comments