Complete Continuous Integration & Deployments on RedHat OpenShift
In this tutorial, we will learn how to create/manage Java-based microservice on OpenShift including:
Nexus3 — the content repository for caching all of our built artifacts, dependencies and docker images.
SonarQube — used for code quality analysis in our build pipeline.
Jenkins — an open-source automation server that enables developers around the world to reliably build, test, and deploy their software.
Steps:
1. Install Jenkins
2. Setup Nexus Repository
3. Install sonarqube
4. Configure Sonarqube in Jenkins
5. Create Jenkins Pipeline
This Git Repository contain all the deployment and configuration files.
Step 1. Install Jenkins
Deploy a Jenkins from configuration available in jenkins folder or else we can use Jenkins built-in template in Openshift.
Use command:
oc apply -f file.yaml
Step 2. Setup Nexus Repository
Similar use the configuration available in nexus repo, once deployment is successful we can see below screen.
We will use maven public repo.
NOTE: Due to any reasons if you are unable to set the environment variable or the build is not using the repo, kindly add nexus_repo_url variable directly to BuildConfig through the OpenShift dashboard.
Step 3. Install Sonarqube
1. Use the config files available under sonarqube folder.
2. Sequence to apply configs (Service account, PVC , deployment, service , route)
3. Once everything is created, we can access Sonarqube and able to see the below screen.
NOTE : For Sonarqube login we can use user:admin password:admin (for me admin:ahsan)
Step 4. Configure Sonarqube in Jenkins
- Install sonar-scanner plugin (From plugin-manager)
- From Global tool congiguration, add SonarQube Scanner installations.
3. We need to create token from Sonarqube
From Sonarqube dashboard, select administration -> security -> users->Tokens
4. Copy the token in Jenkins during configuring SonarQube server
5. Now from the Configuration system, select SonarQube servers
Server URL will be the link of Sonarqube server.
Step 3. Create Jenkins Pipeline
- Login Jenkins
- Then select new-item and then select pipeline. Name it test-pipeline
- In pipeline select pipeline from SCM.
- In Repository pipeline add “https://github.com/mahsankhaan/springboot-openshift.git" and in Script Path add Jenkinsfile.
5. Now run the pipeline and the application must be available in Openshift.
Step 4. Verify Application is running
1. On the left menu of Openshift select Networking and from there select routes.
2. From Openshift left menu, select Networking then routes and from there select the application.