Jenkins Pipeline Setup for On Prem and CloudHub

Jenkins Pipeline Setup for On Prem and CloudHub
Table of Contents
Prerequisites
  • Make sure that Mule server is linked with Anypoint platform for On Prem.
  • Git Bash is installed and running.
STEP 1 – Apache Tomcat 9

Download the Apache Tomcat 9 tar.gz from https://tomcat.apache.org/download-90.cgi

Extract and open the folder in Terminal.

Open the tomcat-users.xml which is available under apache-tomcat-9.0.89/conf folder and add the below content under tomcat-users:

<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>
    

Start Tomcat server from the bin directory.

STEP 2 – Jenkins

Download the Jenkins WAR file from https://www.jenkins.io/download/

Place the WAR file in the webapps folder of Apache Tomcat and restart the server.

Login to Jenkins at: http://localhost:8080/jenkins/login?from=%2Fjenkins%2F

Save the password generated and proceed with the setup process (username will be admin).

STEP 3 – MuleSoft server and Anypoint platform setup
  • Download Mule standalone server and start it from the bin folder. If you face any issues with permissions, go to System settings > Privacy & Security > Allow blocked script.
  • Add the server in Anypoint platform: Runtime Manager > Servers > Add new server > Execute the script generated in the bin folder.
  • Restart the Mule server to get the server reflected on the platform.
STEP 4 – Generating Client ID and Client Secret using the connected apps
  1. Go to the Access Management in the Anypoint platform.
  2. Select Connected Apps and click on “Create App”.
  3. Select “App acts on its own behalf (client credentials)” and add all the scopes.
  4. Note down the generated Client ID and Client Secret.
STEP 5 – Maven Installation

Download Maven from Apache Maven website: https://archive.apache.org/dist/maven/maven-3/

Extract it and note down the path to set the environment variables.

Execute the below commands to set the Maven path:

export M2_HOME=/path/to/maven
export M2=$M2_HOME/bin
export MAVEN_OPTS="-Xms256m -Xmx512m"
export PATH=$M2:$PATH
    

Verify if the Maven path is set by using mvn -version command.

STEP 6 – Generating Git token to avoid MFA
  1. Login to GitHub and go to Settings > Developer Settings > Tokens (classic).
  2. Generate a new token and note it down.
STEP 6 – Maven settings configuration

Open settings.xml in the conf folder of Maven and add the following in the servers section:

<server>
    <id>test</id>
    <username>~~~Client~~~</username>
    <password>your_password_here</password>
</server>
    

Add the following to the profiles section:

<profile>
    <id>mule-ee</id>
    <repositories>
        <repository>
            <id>mule-ee-releases</id>
            <name>MuleEE Releases Repository</name>
            <url>https://repository-master.mulesoft.org/nexus/content/repositories/releases-ee/</url>
        </repository>
        <repository>
            <id>mule-ee-snapshots</id>
            <name>MuleEE Snapshots Repository</name>
            <url>https://repository-master.mulesoft.org/nexus/content/repositories/ci-snapshots/</url>
        </repository>
        <repository>
            <id>MuleRepository</id>
            <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
        </repository>
        <repository>
            <id>MuleRepositoryPublic</id>
            <url>https://repository.mulesoft.org/nexus/content/repositories/public</url>
        </repository>
    </repositories>
</profile>
    
STEP 6 – Updating POM to have the Jenkins configurations

On-Prem Deployment: Add the following under the configurations section:

<armDeployment>
    <muleVersion>${app.runtime}</muleVersion>
    <uri>https://anypoint.mulesoft.com</uri>
    <target>${target}</target>
    <targetType>${target.type}</targetType>
    <server>${runtime.server}</server>
    <environment>${environment}</environment>
    <businessGroup>${businessGroup}</businessGroup>
    <connectedAppClientId>${clientId}</connectedAppClientId>
    <connectedAppClientSecret>${clientSecret}</connectedAppClientSecret>
</armDeployment>
    

CloudHub Deployment:

<cloudHubDeployment>
    <uri>https://anypoint.mulesoft.com</uri>
    <muleVersion>${app.runtime}</muleVersion>
    <connectedAppClientId>${clientId}</connectedAppClientId>
    <connectedAppClientSecret>${clientSecret}</connectedAppClientSecret>
    <environment>${environment}</environment>
    <workers>${workers}</workers>
    <workerType>${workerType}</workerType>
</cloudHubDeployment>
    
STEP 7 – Setting up Jenkins to run a new project
  1. Make sure that Git is installed on your machine.
  2. Go to Jenkins Dashboard and click on “New Item”.
  3. Select “Freestyle project” and give it a relevant name.
  4. Under General, select “GitHub project” and give the project URL.
  5. Under Source Code Management, select Git and provide the repository URL.
  6. Mention branches to build, like */main or */dev.
  7. Select Global credentials for authentication (Username and Git token).
  8. In Build steps, select “Invoke top-level Maven targets”.
  9. For On-Prem, give the following value in the Goals field:
  10. clean deploy -DmuleDeploy -Dtarget=mule-test-server -Denvironment=Design -DbusinessGroup=Test -DclientId=YOUR_CLIENT_ID -DclientSecret=YOUR_CLIENT_SECRET
            
  11. For CloudHub, give the following value:
  12. clean deploy -DmuleDeploy -DclientId=YOUR_CLIENT_ID -DclientSecret=YOUR_CLIENT_SECRET -Dcloudhub.application.name=cloud-hub-app -Denvironment=Sandbox
            
  13. Click “Advanced” in Build steps and give your app name with pom.xml (e.g., test-app/pom.xml).
  14. Save and build your application.

Comments are closed