Author: Manuel George
1. CICD Components
Build Server components:
- OS: Linux server/Windows server
- Jenkins
- Maven 3.6.3
- Jdk 1.8 or above
- Repository: Gitlab
- Deployment Type: Mule Standalone Deployment 4.2.1
- Client Tools Required: Putty
- Sourcetree/Tortoise Git/GithubDesktop
2. Setting up new Gitlab project
- Log into Gitlab account
- Click on the button ‘NewProject’

3. Type the project name, project slug and check the box ‘Initialize the repository with read me’ click create project.
4. Create a dev branch and clone the same to your local system using the any client apps like Source tree, Github Desktop/Tortoise Git
5. Open GithubDesktop and clone the repository using the url retrieved from Gitlab.

- Commit and push the sample code to the dev branch with the jenkins code.

6.

3. Setting up CICD for a new project
3.1 Setting up CICD scripts in Gitlab repository
Jenkinsfile.txt is based on Maven based Deployment and attaching the same below.
pipeline {
agent any
stages {
stage('Build and Deploy to Standalone Server'){
steps {
script{
//defining environment variables based on the opted environment from the job
def deployenv =params.ENVIRONMENT_TO_DEPLOY
def versionv = deployenv+'_DEPLOY_MULE_VERSION'
def targetserverv=deployenv+'_DEPLOY_TARGET_SERVER'
def deployusernamev= deployenv+'_DEPLOY_ANYPOINT_USERNAME'
def deploypasswordv=deployenv+'_DEPLOY_ANYPOINT_PASSWORD'
def anypointurlv=deployenv+'_DEPLOY_ANYPOINT_URL'
def muledeployenvv = deployenv+'_DEPLOY_ENV_NAME'
//Assigning respective variables for deployment
def version = env."${versionv}"
def targetserver=env."${targetserverv}"
def deployusername=env."${deployusernamev}"
def deploypassword=env."${deploypasswordv}"
def anypointurl=env."${anypointurlv}"
def muledeployenv = env."${muledeployenvv}"
//-----getting Application specific variable from config.json
def buildConfig = readJSON file: 'Jenkins/config.json'
def mulekey = buildConfig."${deployenv}".APP_MULEKEY
def muleenv = buildConfig."${deployenv}".ENV
sh """mvn --settings settings.xml clean deploy -Dmule_key=${mulekey} -Dmule_env=${muleenv} -DskipMunitTests -DmuleDeploy -Dmule.version=${version} -Dtarget_server=${targetserver} -Dusername=${deployusername} -Dpassword=${deploypassword} -Denv=${muledeployenv} -Durl=${anypointurl}"""
}
}
}
}
}
Config.json to define -vm args specific to the project.
{
"DEV": {
"APP_MULEKEY": "***************",
"ENV":"dev"
},
"QAS": {
"APP_MULEKEY": "*************",
"ENV":"qas"
},
"PROD": {
"APP_MULEKEY": "***********",
"ENV":"prod"
}
}
POM file – Eg: VM args [properties.key,mule.env, etc…]
POM file update require for CICD:
- Configure ARM deployment config.
- Add the repositories corresponding to the package if not present.
Sample POM has been shared in the folder.
ARM deployment config:
<!-- CICD DEPLOYMENT CONFIG-->
<armDeployment>
<uri>${url}</uri>
<target>${target_server}</target>
<targetType>server</targetType>
<username>${username}</username>
<password>${password}</password>
<environment>${env}</environment>
<properties
<properties.key>${mule_key}
</properties.key>
<mule.env>${mule_env}</mule.env>
</properties>
</armDeployment>
<!-- CICD DEPLOYMENT CONFIG→
3.2. Setting up Jenkins job for the GITLAB project
*Install Git parameter plugin in Jenkins
- Log into Jenkins
- Create a new job called test in Jenkins
- Select the Pipeline job and enter the project name and SCM as Git
- Enter the repository and add credentials as well.
- Set the pipeline script path as well as ‘Jenkins/Jenkinsfile.txt’

6. Add the parameter in Job to display the list of branches to deploy and the anypoint Env in the choice parameter.
*Once the tag is created u can checkout the code from the tag by altering the Parameter type(Branch/Tag) in ListGitBranches

7. Save it.
8. In Manage Jenkins, define the global variables for all the environments.

*These are the variables that will be used in the Jenkinsfile.txt .
4. Munit Test Integration in CICD
Munit testing has been added as a part of CICD deployment.Pipeline will be updated as checkout-> Munit Test -> Build -> Deploy to Standalone server.Below are the changes that has been done as a part of CICD deployment.
Jenkinsfile.txt
Added a new stage called Munit Test in Jenkinsfile.txt which will be reflected in the pipeline.
——————————————————————————————————————
stage('Munit Test'){
steps{ script{
//MUNIT_TEST_CHECK
def munit_test = params.MUNIT_CHECK
if(munit_test == true){
sh """mvn --settings settings.xml clean test"""
}
else {
echo 'MUNIT CHECK IS DISABLED'
}
————————————————————————————–
POM file Update
A maven configuration exclusive to MUnit has to be defined in the build configuration of the POM to make the code maven enabled. As the Munit is intended to DEV all the configs inside the pom are hardcoded with DEV credentials.
<!-- MUNIT CONFIG -->
<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>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<mule.env>dev</mule.env>
<properties.key>*********
</properties.key>
</systemPropertyVariables>
<runtimeVersion>4.2.2-hf4</runtimeVersion>
</configuration>
</plugin>
<!-- MUNIT CONFIG -->
Private repository is inevitable while configuring munit.
<repository>
<id>mulesoft-ee</id>
<name>MuleSoft Releases Repository</name>
<url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
<layout>default</layout>
</repository>
Jenkins UI: Configure Job(for DEV and PROD)Â Define Boolean Build Parameter : MUNIT_CHECK
