Logo

dev-resources.site

for different kinds of informations.

Quick reference: CI/CD for a Mule app using a Connected App

Published at
8/1/2023
Categories
mulesoft
cicd
devops
automation
Author
devalexmartinez
Categories
4 categories in total
mulesoft
open
cicd
open
devops
open
automation
open
Author
15 person written this
devalexmartinez
open
Quick reference: CI/CD for a Mule app using a Connected App

This is intended as a short guide. For detailed instructions + video, please see this series. You can also see this repo.

Connected App

In Anypoint Platform, go to Access Management > Connected Apps > Create app. Select App acts on it's own behalf. Add the scopes:

  • Design Center Developer
  • View Environment
  • View Organization
  • Profile
  • Cloudhub Organization Admin
  • Create Applications
  • Delete Applications
  • Download Applications
  • Read Applications
  • Read Servers

Copy ID and Secret.

GitHub Actions secrets

In your GitHub repo, go to Settings > Secrets and variables > Actions > New repository secret and add the following secrets corresponding to your previous ID and Secret.

  • CONNECTED_APP_CLIENT_ID
  • CONNECTED_APP_CLIENT_SECRET

build.yml

In your Mule app's code or repo, create a .github folder with a workflows folder. Inside this, create a build.yml and paste the following:

name: Build and Deploy

on:
  push:
    branches: [ main ]

jobs:
    build:
        runs-on: ubuntu-latest
        steps:
        - name: Checkout this repo
          uses: actions/checkout@v3
        - name: Cache dependencies
          uses: actions/cache@v3
          with:
            path: ~/.m2/repository
            key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
            restore-keys: |
              ${{ runner.os }}-maven-
        - name: Set up JDK 1.8
          uses: actions/setup-java@v3
          with:
            distribution: 'zulu'
            java-version: 8
        - name: Build with Maven
          run: mvn -B package --file pom.xml -DskipMunitTests
        - name: Stamp artifact file name with commit hash
          run: |
            artifactName1=$(ls target/*.jar | head -1)
            commitHash=$(git rev-parse --short "$GITHUB_SHA")
            artifactName2=$(ls target/*.jar | head -1 | sed "s/.jar/-$commitHash.jar/g")
            mv $artifactName1 $artifactName2
        - name: Upload artifact 
          uses: actions/upload-artifact@v3
          with:
              name: artifacts
              path: target/*.jar

    deploy:
        needs: build
        runs-on: ubuntu-latest
        steps:    
        - name: Checkout this repo
          uses: actions/checkout@v3
        - name: Cache dependencies
          uses: actions/cache@v3
          with:
            path: ~/.m2/repository
            key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
            restore-keys: |
              ${{ runner.os }}-maven-
        - uses: actions/download-artifact@v3
          with:
            name: artifacts
        - name: Deploy
          run: |
            artifactName=$(ls *.jar | head -1)
            mvn deploy -DskipMunitTests -DmuleDeploy \
             -Dmule.artifact=$artifactName \
             -Dclient.id="${{ secrets.CONNECTED_APP_CLIENT_ID }}" \
             -Dclient.secret="${{ secrets.CONNECTED_APP_CLIENT_SECRET }}"
Enter fullscreen mode Exit fullscreen mode

pom.xml

Make sure the config matches your application. For example, muleVersion, applicationName, environment, region, and so on.

<plugin>
  <groupId>org.mule.tools.maven</groupId>
  <artifactId>mule-maven-plugin</artifactId>
  <version>${mule.maven.plugin.version}</version>
  <extensions>true</extensions>
  <!-- Deployment config start -->
  <configuration>
    <cloudHubDeployment>
      <uri>https://anypoint.mulesoft.com</uri>
      <muleVersion>4.4.0</muleVersion>
      <applicationName>mulesoft-mfa-cicd</applicationName>
      <environment>Sandbox</environment>
      <workerType>MICRO</workerType>
      <region>us-east-2</region>
      <workers>1</workers>
      <objectStoreV2>true</objectStoreV2>
      <connectedAppClientId>${client.id}</connectedAppClientId>
      <connectedAppClientSecret>${client.secret}</connectedAppClientSecret>
      <connectedAppGrantType>client_credentials</connectedAppGrantType>
      <properties>
        <env>${env}</env>
      </properties>
    </cloudHubDeployment>
  </configuration>
  <!-- Deployment config end -->
</plugin>
Enter fullscreen mode Exit fullscreen mode

That's it! Commit, push, and watch it run :)

mulesoft Article's
30 articles in total
Favicon
Top Use Cases of MuleSoft API Manager
Favicon
List of AsyncAPI servers in MuleSoft
Favicon
Comparison Of Boomi And Mulesoft: Choosing The Right Integration Platform
Favicon
MuleSoft RPA Basics: From Start to Finish
Favicon
Quick fix: com.github.everit-org.json-schema:org.everit.json.schema:jar:1.12.2 was not found
Favicon
The Ultimate Guide to Mastering MuleSoft: Elevate Your Integration Skills
Favicon
How to Improve Productivity with MuleSoft RPA Integration
Favicon
Integration Digest: March 2024
Favicon
4 ways to retrieve your OrgID/groupID from Anypoint Platform
Favicon
An interesting Mule app to create complex MUnits
Favicon
Methods for Handling Null Values in DataWeave
Favicon
Quick guide to applying MuleSoft's API Autodiscovery
Favicon
Quick guide to secure/encrypt your properties in MuleSoft
Favicon
Integration Digest: October 2023
Favicon
Integration Digest: November 2023
Favicon
mTLS in CloudHub 2.0 : What Developers Need to Know
Favicon
Harnessing the power of MuleSoft and Hasura
Favicon
How to Set HTTP Error Responses in MUnit Testing
Favicon
Quick reference: CI/CD for a Mule app using a Connected App
Favicon
Mastering RAML Resource Naming: Best Practices for a MuleSoft Marvel! 💻🚀
Favicon
Leverage Exchange Mocking Service with Mocking Service Proxy
Favicon
Best Mulesoft Service Providers
Favicon
Using time() and duration() in DataWeave for performance check
Favicon
Deploying MuleSoft Application to Cloudhub 2.0 using Azure DevOps - Part 2
Favicon
Deploying MuleSoft Application to Cloudhub 2.0 using Azure DevOps - Part 1
Favicon
Main difference between 'do' and 'using' operators in DataWeave
Favicon
Develop your Battlesnake using a MuleSoft API & DataWeave with this starter project
Favicon
How to generate shareable link examples from GitHub to open in the DataWeave Playground
Favicon
Custom Alerts and Notifications in CloudHub 2.0
Favicon
Read this book to get started with MuleSoft! Especially if you come from a Salesforce background

Featured ones: