MuleSoft

MuleSoft CI/CD Pipeline with Maven and GitHub Actions

Petru Constantin
••13 min read
#mulesoft#cicd#maven#github-actions#devops#automation

A MuleSoft CI/CD pipeline needs three parts: the Mule Maven Plugin, which publishes the application to Exchange and deploys it to CloudHub 2.0 or Runtime Fabric; the MUnit Maven plugin, which runs the tests and enforces a coverage threshold; and a GitHub Actions workflow that authenticates with a Connected App instead of a user account. This guide builds each part, with the configuration checked against the current plugin documentation.

Petru Constantin is a MuleSoft Certified Developer Level 2 (2025) and has built MuleSoft APIs for enterprise integration since 2022. Code examples are written against the Mule 4.9 LTS, Mule Maven Plugin 4.10.4 and MUnit 3.7.6 documentation.

CI/CD Architecture Overview

┌─────────────────────────────────────────────────────────────────────────┐
│                    MULESOFT CI/CD PIPELINE                              │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                         │
│   DEVELOPER                    GITHUB                                   │
│  ┌─────────────┐            ┌────────────────────────────────────────┐ │
│  │   Commit    │───push────►│                                        │ │
│  │   Code      │            │   ┌──────────────────────────────────┐ │ │
│  └─────────────┘            │   │     GITHUB ACTIONS WORKFLOW      │ │ │
│                             │   │                                  │ │ │
│                             │   │  1. Checkout Code                │ │ │
│                             │   │  2. Setup JDK 17 + Maven cache   │ │ │
│                             │   │  3. Run MUnit Tests + Coverage   │ │ │
│                             │   │  4. Package Application          │ │ │
│                             │   │  5. Publish to Exchange          │ │ │
│                             │   │  6. Deploy (Connected App)       │ │ │
│                             │   │                                  │ │ │
│                             │   └──────────────────────────────────┘ │ │
│                             │              │                         │ │
│                             └──────────────┼─────────────────────────┘ │
│                                            │                           │
│                                            ▼                           │
│   ANYPOINT PLATFORM        ┌────────────────────────────────────────┐ │
│  ┌─────────────────────────┤         DEPLOYMENT TARGETS             │ │
│  │                         └────────────────────────────────────────┘ │
│  │   ┌─────────────┐   ┌─────────────┐   ┌─────────────┐            │
│  │   │ CloudHub 2.0│   │ CloudHub 2.0│   │   Runtime   │            │
│  │   │   (DEV)     │   │   (PROD)    │   │   Fabric    │            │
│  │   └─────────────┘   └─────────────┘   └─────────────┘            │
│  └───────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘

Maven Project Configuration

pom.xml Setup

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <!-- To publish to Exchange, groupId must be your organization (or business group) ID -->
    <groupId>00000000-0000-0000-0000-000000000000</groupId>
    <artifactId>orders-api</artifactId>
    <version>1.0.0</version>
    <packaging>mule-application</packaging>
 
    <name>Orders API</name>
    <description>Order Management System API</description>
 
    <properties>
        <!-- Runtime used by Studio and MUnit -->
        <app.runtime>4.9.0</app.runtime>
 
        <!-- Plugin Versions -->
        <mule.maven.plugin.version>4.10.4</mule.maven.plugin.version>
        <munit.version>3.7.6</munit.version>
 
        <!-- Deployment defaults (overridden by the profiles below) -->
        <deploy.environment>Sandbox</deploy.environment>
        <deploy.suffix>dev</deploy.suffix>
        <!-- Shared space or private space name, as listed in Runtime Manager -->
        <ch2.target>Cloudhub-US-East-1</ch2.target>
        <ch2.replicas>1</ch2.replicas>
        <ch2.vCores>0.1</ch2.vCores>
 
        <!-- Connected App credentials (from CI/CD secrets) -->
        <anypoint.client.id>${env.ANYPOINT_CLIENT_ID}</anypoint.client.id>
        <anypoint.client.secret>${env.ANYPOINT_CLIENT_SECRET}</anypoint.client.secret>
        <anypoint.org.id>${env.ANYPOINT_ORG_ID}</anypoint.org.id>
    </properties>
 
    <dependencies>
        <!-- MUnit runner and tools, test scope -->
        <dependency>
            <groupId>com.mulesoft.munit</groupId>
            <artifactId>munit-runner</artifactId>
            <version>${munit.version}</version>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.munit</groupId>
            <artifactId>munit-tools</artifactId>
            <version>${munit.version}</version>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>
    </dependencies>
 
    <build>
        <plugins>
            <!-- Mule Maven Plugin -->
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>${mule.maven.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <!-- CloudHub 2.0 Deployment Configuration -->
                    <cloudhub2Deployment>
                        <uri>https://anypoint.mulesoft.com</uri>
                        <provider>MC</provider>
                        <environment>${deploy.environment}</environment>
                        <target>${ch2.target}</target>
                        <releaseChannel>LTS</releaseChannel>
                        <javaVersion>17</javaVersion>
                        <connectedAppClientId>${anypoint.client.id}</connectedAppClientId>
                        <connectedAppClientSecret>${anypoint.client.secret}</connectedAppClientSecret>
                        <connectedAppGrantType>client_credentials</connectedAppGrantType>
                        <applicationName>${project.artifactId}-${deploy.suffix}</applicationName>
                        <businessGroupId>${anypoint.org.id}</businessGroupId>
                        <replicas>${ch2.replicas}</replicas>
                        <vCores>${ch2.vCores}</vCores>
                        <properties>
                            <env>${deploy.suffix}</env>
                        </properties>
                        <secureProperties>
                            <db.password>${env.DB_PASSWORD}</db.password>
                            <api.client.secret>${env.API_CLIENT_SECRET}</api.client.secret>
                        </secureProperties>
                    </cloudhub2Deployment>
                </configuration>
            </plugin>
 
            <!-- MUnit Plugin -->
            <plugin>
                <groupId>com.mulesoft.munit.tools</groupId>
                <artifactId>munit-maven-plugin</artifactId>
                <version>${munit.version}</version>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                            <goal>coverage-report</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <coverage>
                        <runCoverage>true</runCoverage>
                        <failBuild>true</failBuild>
                        <requiredApplicationCoverage>80</requiredApplicationCoverage>
                        <requiredFlowCoverage>80</requiredFlowCoverage>
                        <formats>
                            <format>console</format>
                            <format>html</format>
                        </formats>
                    </coverage>
                    <runtimeVersion>${app.runtime}</runtimeVersion>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
    <!-- Exchange Maven facade: CloudHub 2.0 deploys the asset published here -->
    <distributionManagement>
        <repository>
            <id>anypoint-exchange-v3</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${project.groupId}/maven</url>
            <layout>default</layout>
        </repository>
    </distributionManagement>
 
    <repositories>
        <repository>
            <id>anypoint-exchange-v3</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${project.groupId}/maven</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mule-public</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
            <layout>default</layout>
        </repository>
    </repositories>
 
    <pluginRepositories>
        <pluginRepository>
            <id>mule-public</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
            <layout>default</layout>
        </pluginRepository>
    </pluginRepositories>
 
    <!-- Deployment Profiles -->
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <deploy.environment>Sandbox</deploy.environment>
                <deploy.suffix>dev</deploy.suffix>
                <ch2.replicas>1</ch2.replicas>
                <ch2.vCores>0.1</ch2.vCores>
            </properties>
        </profile>
 
        <profile>
            <id>qa</id>
            <properties>
                <deploy.environment>QA</deploy.environment>
                <deploy.suffix>qa</deploy.suffix>
                <ch2.replicas>1</ch2.replicas>
                <ch2.vCores>0.2</ch2.vCores>
            </properties>
        </profile>
 
        <profile>
            <id>prod</id>
            <properties>
                <deploy.environment>Production</deploy.environment>
                <deploy.suffix>prod</deploy.suffix>
                <ch2.replicas>2</ch2.replicas>
                <ch2.vCores>0.5</ch2.vCores>
            </properties>
        </profile>
 
        <!-- Runtime Fabric Profile: replaces the CloudHub 2.0 configuration -->
        <profile>
            <id>rtf</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.mule.tools.maven</groupId>
                        <artifactId>mule-maven-plugin</artifactId>
                        <version>${mule.maven.plugin.version}</version>
                        <configuration combine.self="override">
                            <runtimeFabricDeployment>
                                <uri>https://anypoint.mulesoft.com</uri>
                                <provider>MC</provider>
                                <environment>${rtf.environment}</environment>
                                <target>${rtf.target}</target>
                                <releaseChannel>LTS</releaseChannel>
                                <javaVersion>17</javaVersion>
                                <connectedAppClientId>${anypoint.client.id}</connectedAppClientId>
                                <connectedAppClientSecret>${anypoint.client.secret}</connectedAppClientSecret>
                                <connectedAppGrantType>client_credentials</connectedAppGrantType>
                                <applicationName>${project.artifactId}</applicationName>
                                <businessGroupId>${anypoint.org.id}</businessGroupId>
                                <replicas>2</replicas>
                                <deploymentSettings>
                                    <updateStrategy>rolling</updateStrategy>
                                    <clustered>true</clustered>
                                    <resources>
                                        <cpu>
                                            <reserved>100m</reserved>
                                            <limit>500m</limit>
                                        </cpu>
                                        <memory>
                                            <reserved>1000Mi</reserved>
                                        </memory>
                                    </resources>
                                    <http>
                                        <inbound>
                                            <publicUrl>${rtf.public.url}</publicUrl>
                                        </inbound>
                                    </http>
                                </deploymentSettings>
                            </runtimeFabricDeployment>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
 
</project>

Maven Settings (settings.xml)

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
          https://maven.apache.org/xsd/settings-1.0.0.xsd">
 
    <servers>
        <!-- Anypoint Exchange with Connected App credentials.
             The id must match the repository / distributionManagement id in pom.xml -->
        <server>
            <id>anypoint-exchange-v3</id>
            <username>~~~Client~~~</username>
            <password>${env.ANYPOINT_CLIENT_ID}~?~${env.ANYPOINT_CLIENT_SECRET}</password>
        </server>
 
        <!-- If your subscription gives you access to the MuleSoft Enterprise repository,
             add its server entry here with the credentials MuleSoft provides -->
    </servers>
 
</settings>

GitHub Actions Workflows

Main CI/CD Workflow

# .github/workflows/mule-cicd.yml
name: MuleSoft CI/CD Pipeline
 
on:
  push:
    branches: [main, develop, 'release/*']
  pull_request:
    branches: [main, develop]
  workflow_dispatch:
    inputs:
      environment:
        description: 'Deployment environment'
        required: true
        default: 'dev'
        type: choice
        options:
          - dev
          - qa
          - prod
 
env:
  JAVA_VERSION: '17'
 
jobs:
  # Build and Test Job
  build-and-test:
    name: Build and Test
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout Code
        uses: actions/checkout@v7
 
      - name: Set up JDK ${{ env.JAVA_VERSION }}
        uses: actions/setup-java@v6
        with:
          java-version: ${{ env.JAVA_VERSION }}
          distribution: 'temurin'
          cache: maven
 
      - name: Configure Maven Settings
        run: |
          set -euo pipefail
          mkdir -p ~/.m2
          cat << EOF > ~/.m2/settings.xml
          <settings>
            <servers>
              <server>
                <id>anypoint-exchange-v3</id>
                <username>~~~Client~~~</username>
                <password>${ANYPOINT_CLIENT_ID}~?~${ANYPOINT_CLIENT_SECRET}</password>
              </server>
            </servers>
          </settings>
          EOF
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
 
      # The test phase runs MUnit and the coverage check configured in pom.xml
      - name: Build, Test and Package
        run: mvn -B clean package
 
      - name: Upload MUnit Reports
        uses: actions/upload-artifact@v7
        if: always()
        with:
          name: munit-reports
          path: target/site/munit/
 
      - name: Upload Artifact
        uses: actions/upload-artifact@v7
        with:
          name: mule-artifact
          path: target/*.jar
          retention-days: 5
 
  # Deploy to Development (publishes to Exchange, then deploys)
  deploy-dev:
    name: Deploy to Development
    runs-on: ubuntu-latest
    needs: build-and-test
    if: (github.event_name == 'push' && github.ref == 'refs/heads/develop') || github.event.inputs.environment == 'dev'
    environment: development
 
    steps:
      - name: Checkout Code
        uses: actions/checkout@v7
 
      - name: Set up JDK
        uses: actions/setup-java@v6
        with:
          java-version: ${{ env.JAVA_VERSION }}
          distribution: 'temurin'
          cache: maven
 
      - name: Configure Maven Settings
        run: |
          set -euo pipefail
          mkdir -p ~/.m2
          cat << EOF > ~/.m2/settings.xml
          <settings>
            <servers>
              <server>
                <id>anypoint-exchange-v3</id>
                <username>~~~Client~~~</username>
                <password>${ANYPOINT_CLIENT_ID}~?~${ANYPOINT_CLIENT_SECRET}</password>
              </server>
            </servers>
          </settings>
          EOF
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
 
      # Secrets reach the pom through ${env.*}, not through the command line
      - name: Deploy to CloudHub 2.0 (Dev)
        run: mvn -B clean deploy -DmuleDeploy -Pdev -DskipTests
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
          ANYPOINT_ORG_ID: ${{ secrets.ANYPOINT_ORG_ID }}
          DB_PASSWORD: ${{ secrets.DEV_DB_PASSWORD }}
          API_CLIENT_SECRET: ${{ secrets.DEV_API_CLIENT_SECRET }}
 
      - name: Verify Deployment
        run: |
          set -euo pipefail
          curl --fail --silent --show-error --retry 10 --retry-delay 15 --retry-all-errors \
            "${{ vars.DEV_HEALTH_URL }}"
 
  # Deploy to QA from release branches
  deploy-qa:
    name: Deploy to QA
    runs-on: ubuntu-latest
    needs: build-and-test
    if: (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/')) || github.event.inputs.environment == 'qa'
    environment: qa
 
    steps:
      - name: Checkout Code
        uses: actions/checkout@v7
 
      - name: Set up JDK
        uses: actions/setup-java@v6
        with:
          java-version: ${{ env.JAVA_VERSION }}
          distribution: 'temurin'
          cache: maven
 
      - name: Configure Maven Settings
        run: |
          set -euo pipefail
          mkdir -p ~/.m2
          cat << EOF > ~/.m2/settings.xml
          <settings>
            <servers>
              <server>
                <id>anypoint-exchange-v3</id>
                <username>~~~Client~~~</username>
                <password>${ANYPOINT_CLIENT_ID}~?~${ANYPOINT_CLIENT_SECRET}</password>
              </server>
            </servers>
          </settings>
          EOF
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
 
      # The asset version is already in Exchange: deploy it without rebuilding
      - name: Deploy to CloudHub 2.0 (QA)
        run: mvn -B mule:deploy -Pqa
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
          ANYPOINT_ORG_ID: ${{ secrets.ANYPOINT_ORG_ID }}
          DB_PASSWORD: ${{ secrets.QA_DB_PASSWORD }}
          API_CLIENT_SECRET: ${{ secrets.QA_API_CLIENT_SECRET }}
 
  # Deploy to Production (protect the "production" environment with required reviewers)
  deploy-prod:
    name: Deploy to Production
    runs-on: ubuntu-latest
    needs: build-and-test
    if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event.inputs.environment == 'prod'
    environment: production
    permissions:
      contents: write
 
    steps:
      - name: Checkout Code
        uses: actions/checkout@v7
 
      - name: Set up JDK
        uses: actions/setup-java@v6
        with:
          java-version: ${{ env.JAVA_VERSION }}
          distribution: 'temurin'
          cache: maven
 
      - name: Configure Maven Settings
        run: |
          set -euo pipefail
          mkdir -p ~/.m2
          cat << EOF > ~/.m2/settings.xml
          <settings>
            <servers>
              <server>
                <id>anypoint-exchange-v3</id>
                <username>~~~Client~~~</username>
                <password>${ANYPOINT_CLIENT_ID}~?~${ANYPOINT_CLIENT_SECRET}</password>
              </server>
            </servers>
          </settings>
          EOF
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
 
      - name: Deploy to CloudHub 2.0 (Production)
        run: mvn -B mule:deploy -Pprod
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
          ANYPOINT_ORG_ID: ${{ secrets.ANYPOINT_ORG_ID }}
          DB_PASSWORD: ${{ secrets.PROD_DB_PASSWORD }}
          API_CLIENT_SECRET: ${{ secrets.PROD_API_CLIENT_SECRET }}
 
      - name: Verify Production Deployment
        run: |
          set -euo pipefail
          curl --fail --silent --show-error --retry 10 --retry-delay 15 --retry-all-errors \
            "${{ vars.PROD_HEALTH_URL }}"
 
      - name: Create Release Tag
        run: |
          set -euo pipefail
          VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
          git tag "v${VERSION}-$(date +%Y%m%d%H%M%S)"
          git push origin --tags

Runtime Fabric Deployment Workflow

# .github/workflows/mule-rtf-deploy.yml
name: Deploy to Runtime Fabric
 
on:
  workflow_dispatch:
    inputs:
      environment:
        description: 'RTF Environment'
        required: true
        type: choice
        options:
          - rtf-dev
          - rtf-prod
      target:
        description: 'RTF Target Name'
        required: true
        default: 'rtf-cluster-1'
 
jobs:
  deploy-rtf:
    name: Deploy to RTF
    runs-on: ubuntu-latest
    environment: ${{ github.event.inputs.environment }}
 
    steps:
      - name: Checkout Code
        uses: actions/checkout@v7
 
      - name: Set up JDK 17
        uses: actions/setup-java@v6
        with:
          java-version: '17'
          distribution: 'temurin'
          cache: maven
 
      - name: Configure Maven Settings
        run: |
          set -euo pipefail
          mkdir -p ~/.m2
          cat << EOF > ~/.m2/settings.xml
          <settings>
            <servers>
              <server>
                <id>anypoint-exchange-v3</id>
                <username>~~~Client~~~</username>
                <password>${ANYPOINT_CLIENT_ID}~?~${ANYPOINT_CLIENT_SECRET}</password>
              </server>
            </servers>
          </settings>
          EOF
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
 
      - name: Deploy to Runtime Fabric
        run: |
          set -euo pipefail
          mvn -B clean deploy -DmuleDeploy -Prtf -DskipTests \
            -Drtf.target="${{ github.event.inputs.target }}" \
            -Drtf.environment="${{ github.event.inputs.environment }}" \
            -Drtf.public.url="${{ vars.RTF_PUBLIC_URL }}"
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
          ANYPOINT_ORG_ID: ${{ secrets.ANYPOINT_ORG_ID }}
 
      - name: Verify RTF Deployment
        run: |
          set -euo pipefail
          curl --fail --silent --show-error --retry 10 --retry-delay 15 --retry-all-errors \
            "${{ vars.RTF_PUBLIC_URL }}/api/health"

Publish to Exchange Workflow

# .github/workflows/publish-exchange.yml
name: Publish to Anypoint Exchange
 
on:
  release:
    types: [published]
  workflow_dispatch:
 
jobs:
  publish:
    name: Publish to Exchange
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout Code
        uses: actions/checkout@v7
 
      - name: Set up JDK 17
        uses: actions/setup-java@v6
        with:
          java-version: '17'
          distribution: 'temurin'
          cache: maven
 
      - name: Configure Maven Settings
        run: |
          set -euo pipefail
          mkdir -p ~/.m2
          cat << EOF > ~/.m2/settings.xml
          <settings>
            <servers>
              <server>
                <id>anypoint-exchange-v3</id>
                <username>~~~Client~~~</username>
                <password>${ANYPOINT_CLIENT_ID}~?~${ANYPOINT_CLIENT_SECRET}</password>
              </server>
            </servers>
          </settings>
          EOF
        env:
          ANYPOINT_CLIENT_ID: ${{ secrets.ANYPOINT_CLIENT_ID }}
          ANYPOINT_CLIENT_SECRET: ${{ secrets.ANYPOINT_CLIENT_SECRET }}
 
      - name: Set Version from Tag
        if: github.event_name == 'release'
        run: |
          set -euo pipefail
          VERSION="${GITHUB_REF#refs/tags/v}"
          mvn -B versions:set -DnewVersion="$VERSION"
 
      # distributionManagement in pom.xml points to the Exchange Maven facade
      - name: Publish to Exchange
        run: mvn -B deploy -DskipTests

MUnit Testing Configuration

Sample MUnit Test

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
      xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core
        http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/munit
        http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
        http://www.mulesoft.org/schema/mule/munit-tools
        http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd">
 
    <munit:config name="orders-api-test-suite.xml"/>
 
    <!-- Test: Create Order - Success -->
    <munit:test name="create-order-success-test"
                description="Test successful order creation">
 
        <munit:behavior>
            <!-- Mock database insert -->
            <munit-tools:mock-when processor="db:insert" doc:name="Mock DB Insert">
                <munit-tools:with-attributes>
                    <munit-tools:with-attribute
                        attributeName="doc:name"
                        whereValue="Insert Order"/>
                </munit-tools:with-attributes>
                <munit-tools:then-return>
                    <munit-tools:payload value="#[1]"/>
                </munit-tools:then-return>
            </munit-tools:mock-when>
 
            <!-- Mock external API call -->
            <munit-tools:mock-when processor="http:request" doc:name="Mock HTTP Request">
                <munit-tools:with-attributes>
                    <munit-tools:with-attribute
                        attributeName="doc:name"
                        whereValue="Call Inventory Service"/>
                </munit-tools:with-attributes>
                <munit-tools:then-return>
                    <munit-tools:payload value="#[{available: true, quantity: 100}]"/>
                </munit-tools:then-return>
            </munit-tools:mock-when>
        </munit:behavior>
 
        <munit:execution>
            <set-payload value='#[{
                "customerId": "CUST-001",
                "items": [
                    {"productId": "PROD-001", "quantity": 2},
                    {"productId": "PROD-002", "quantity": 1}
                ]
            }]' mimeType="application/json"/>
 
            <flow-ref name="create-order-flow"/>
        </munit:execution>
 
        <!-- flow-ref calls the flow directly, so assert on payload and vars, not on HTTP attributes -->
        <munit:validation>
            <munit-tools:assert-that
                expression="#[payload.orderId]"
                is="#[MunitTools::notNullValue()]"
                message="Response should contain orderId"/>
 
            <munit-tools:assert-that
                expression="#[payload.status]"
                is="#[MunitTools::equalTo('CREATED')]"
                message="Order status should be CREATED"/>
        </munit:validation>
 
    </munit:test>
 
    <!-- Test: Create Order - Validation Error -->
    <munit:test name="create-order-validation-error-test"
                description="Test order creation with invalid data"
                expectedErrorType="APP:VALIDATION_ERROR">
 
        <munit:execution>
            <!-- Missing required fields -->
            <set-payload value='#[{
                "items": []
            }]' mimeType="application/json"/>
 
            <flow-ref name="create-order-flow"/>
        </munit:execution>
 
    </munit:test>
 
    <!-- Test: Get Order - Found -->
    <munit:test name="get-order-found-test"
                description="Test retrieving existing order">
 
        <munit:behavior>
            <munit-tools:mock-when processor="db:select" doc:name="Mock DB Select">
                <munit-tools:then-return>
                    <munit-tools:payload value="#[[{
                        order_id: 'ORD-12345',
                        customer_id: 'CUST-001',
                        status: 'PROCESSING',
                        total: 150.00
                    }]]"/>
                </munit-tools:then-return>
            </munit-tools:mock-when>
        </munit:behavior>
 
        <munit:execution>
            <set-variable variableName="orderId" value="ORD-12345"/>
            <flow-ref name="get-order-flow"/>
        </munit:execution>
 
        <munit:validation>
            <munit-tools:assert-that
                expression="#[payload.orderId]"
                is="#[MunitTools::equalTo('ORD-12345')]"/>
        </munit:validation>
 
    </munit:test>
 
    <!-- Test: Get Order - Not Found -->
    <munit:test name="get-order-not-found-test"
                description="Test retrieving non-existent order"
                expectedErrorType="APP:NOT_FOUND">
 
        <munit:behavior>
            <munit-tools:mock-when processor="db:select">
                <munit-tools:then-return>
                    <munit-tools:payload value="#[[]]"/>
                </munit-tools:then-return>
            </munit-tools:mock-when>
        </munit:behavior>
 
        <munit:execution>
            <set-variable variableName="orderId" value="NON-EXISTENT"/>
            <flow-ref name="get-order-flow"/>
        </munit:execution>
 
    </munit:test>
 
</mule>

GitHub Secrets Configuration

Required Secrets

# GitHub repository secrets (Settings > Secrets and variables > Actions)
 
# Anypoint Platform Connected App (client_credentials)
ANYPOINT_CLIENT_ID: "connected-app-client-id"
ANYPOINT_CLIENT_SECRET: "connected-app-client-secret"
ANYPOINT_ORG_ID: "org-or-business-group-id"
 
# Environment-specific secrets (read by the pom through ${env.*})
DEV_DB_PASSWORD: "dev-database-password"
DEV_API_CLIENT_SECRET: "dev-api-secret"
 
QA_DB_PASSWORD: "qa-database-password"
QA_API_CLIENT_SECRET: "qa-api-secret"
 
PROD_DB_PASSWORD: "prod-database-password"
PROD_API_CLIENT_SECRET: "prod-api-secret"
 
# Repository variables (not secret)
DEV_HEALTH_URL: "https://orders-api-dev.example.com/api/health"
PROD_HEALTH_URL: "https://orders-api.example.com/api/health"
RTF_PUBLIC_URL: "https://api.example.com"

Common mistakes

  • Deploying an asset that is not in Exchange. The CloudHub 2.0 deployment page lists "The application is already published in Exchange" as a prerequisite, and the Exchange Maven facade has to be in distributionManagement. mvn clean deploy -DmuleDeploy covers both in one run; mvn mule:deploy deploys without rebuilding.
  • Leaving javaVersion and releaseChannel on their defaults. For cloudhub2Deployment, javaVersion defaults to 8 and releaseChannel defaults to EDGE. Mule 4.9 LTS runs on Java 17, so set both explicitly.
  • A Connected App without the right scope. The plugin documentation notes that the Connected App credentials must have the Design Center Developer access scope.
  • Keeping CloudHub 1.0 settings in a CloudHub 2.0 pom. workers, workerType and region belong to cloudHubDeployment. CloudHub 2.0 uses target, replicas and vCores (0.1 to 4 vCores per replica).

Best Practices Summary

cicd_best_practices:
  pipeline_design:
    - "Use branch-based deployment (develop → QA, main → Prod)"
    - "Implement environment approvals for production"
    - "Cache Maven dependencies to speed up builds"
    - "Run tests in parallel when possible"
    - "Fail fast on test failures"
 
  security:
    - "Store all credentials in GitHub Secrets"
    - "Use Connected Apps instead of user credentials"
    - "Run OWASP dependency checks"
    - "Scan for secrets in code"
    - "Use environment-specific secrets"
 
  testing:
    - "Enforce minimum 80% code coverage"
    - "Mock external dependencies in tests"
    - "Run integration tests in CI"
    - "Upload test reports as artifacts"
 
  deployment:
    - "Use Maven profiles for environment configuration"
    - "Implement health checks post-deployment"
    - "Tag releases after successful production deployment"
    - "Use blue-green or rolling deployments for zero downtime"
 
  monitoring:
    - "Configure deployment notifications (Slack, Teams)"
    - "Set up deployment tracking in monitoring tools"
    - "Log deployment metadata for traceability"
    - "Monitor deployment success/failure rates"

Conclusion

Automating MuleSoft CI/CD with Maven and GitHub Actions streamlines deployments across CloudHub and Runtime Fabric. Key practices include using Connected Apps for authentication, environment-specific profiles, comprehensive MUnit testing, and security scanning. This pipeline ensures reliable, repeatable deployments with proper governance.


Official references

Related on this site: MuleSoft Anypoint MQ Guide: Queues, FIFO, DLQ and ACK Modes, MuleSoft API-Led Connectivity: Architecture Guide, CloudHub vs Runtime Fabric: Complete Comparison Guide. More articles in the MuleSoft category, and the engineering work behind them is on the services page.

Need an AI system built and running in production, with the scope agreed in writing and a delivery guarantee? See how a DeviDevs Sprint works →

Want AI agents and automations your business can actually run on?

We ship production AI in fixed two-week sprints, then secure them. Book a 30-minute call to scope yours.

Book a Call

Before you book, you can see what we build, how a sprint works, how our pricing works, what we have already built, or write to us directly.

Weekly AI Agents, Automation & Security Digest

How we build AI agents and automations with Claude Code, plus practical AI security, integrations, and platform notes, delivered weekly.

No spam. Unsubscribe anytime.