DEV Community

Cover image for Jenkins CICD
bharatrajtj
bharatrajtj

Posted on

Jenkins CICD

  • Provision an EC2 instance on AWS, opting for the t2.large configuration that supports 2 CPUs and 8GB of RAM. This ensures ample computational power and memory resources to support our Jenkins project's requirements effectively.

Image description

Image description

  • Install Java, a prerequisite for Jenkins' operation. This ensures the availability of the Java Runtime Environment (JRE), essential for executing Jenkins and its associated processes smoothly.

Image description

  • Execute the Jenkins installation script to commence the setup process. This script initiates the installation procedure, configuring Jenkins' core components and preparing the environment for subsequent configuration steps.

Image description

  • By default, Jenkins operates its HTTP service on port 8080. This configuration allows for access to the Jenkins web interface.

Image description

  • Establish inbound traffic rules within the AWS security group associated with your EC2 instance to facilitate communication on port 8080.

Image description

  • Access the initial administrative password for Jenkins by executing the command cat /var/lib/jenkins/secrets/initialAdminPassword within your EC2 terminal. This step retrieves the required credential, enabling you to proceed with the initial setup and configuration of your Jenkins instance.

Image description

Image description

  • Upon completing the installation of the required plugins and finalizing the setup process, you will be directed to the Jenkins Dashboard. This central hub serves as the control panel for managing your Jenkins environment, offering access to various features and functionalities essential for orchestrating automation tasks and pipelines effectively.

Image description

  • Navigate to the "New Item" option within the Jenkins interface to initiate the creation of a new Jenkins Pipeline. Opt for the Pipeline project type to configure and manage your pipeline's workflow, facilitating streamlined automation and continuous integration within your development environment.

Image description

  • Choose "Pipeline script from SCM" as the configuration option for your Jenkins Pipeline. Given that Git serves as our Source Code Manager (SCM) for this project, specify the repository URL as https://github.com/bharatrajtj/jenkins.

Image description

  • Specify the "Script Path" as the directory path within the repository where the Jenkinsfile is located.

Image description

  • Navigate to "Manage Jenkins" > "Manage Plugins" > "Available" tab, and search for the "Docker Pipeline" plugin. Proceed to install this plugin to enable the utilization of Docker containers as agents within your Jenkins environment.

Image description

Image description

  • Navigate to "Manage Jenkins" > "Manage Plugins" > "Available" tab, and search for the "SonarQube Scanner" plugin. Install this plugin to enable seamless integration of SonarQube for code quality inspection within your Jenkins environment.

Image description

  • Add new user named SonarQube in the EC2 instance and switch to the new user

Image description

Image description

  • To unzip the downloaded SonarQube zip file, you'll need to have the unzip utility installed on your system. You can install it using the apt package manager.

Image description

  • Switch to sonarqube user and run unzip *

Image description

Image description

  • Grant permission to the folders

Image description

  • Go to the path depending upon your instance architecture

Image description

  • Run ./sonar.sh start to execute your SonarQube server

Image description

  • Configure inbound rules within your EC2 instance's security group to allow traffic from port 9000, the default port for SonarQube. This step ensures that incoming traffic on port 9000 is permitted, enabling access to the SonarQube application.

Image description

  • Access the SonarQube server page by entering your EC2 instance's IP address followed by ":9000" in your web browser's address bar. Upon reaching the SonarQube server page, use the default credentials to log in:

Username: admin
Password: admin

Image description

Image description

  • In the SonarQube web interface, navigate to "My Account" and then to "Security" settings. Locate the option to generate an access token, found within the user profile or security settings.

This token will be used to configure the integration between SonarQube and Jenkins. Ensure you securely store the token as it grants access to SonarQube resources.

Image description

  • In Jenkins Page go to ManageJenkins>Credentials>System>GlobalCredentials>AddCredentials to enter sonarqube token

Image description

Image description

  • Install Docker in root user in your EC2 terminal

Image description

  • Grant Jenkins and Ubuntu user permission to access docker daemon and restart docker

Image description

  • Restart Jenkins to make sure the plugins installed will function properly. To restart jenkins after port number enter /restart

Image description

  • Run Minikube on your local machine through docker as the driver

Image description

  • Install the ArgoCD operator to streamline the lifecycle management of the Kubernetes controller, ArgoCD, within your Minikube environment. Utilize the resources available at https://operatorhub.io/operator/argocd-operator to access and deploy the operator.

Image description

  • Configure DockerHub and GitHub credentials within Jenkins to facilitate seamless integration with these platforms.

Image description

  • For GitHub, navigate to "Settings," then "Personal access tokens," and proceed to "Generate New token (classic)" to create a new token. This token will serve as the authentication mechanism for Jenkins to interact with your GitHub repositories securely.

Image description

  • Within Jenkins, employ the "Secret text" type to configure GitHub credentials securely. After creating the credentials, ensure to restart Jenkins to enact the changes and enable seamless authentication for GitHub interactions within your Jenkins environment.

Image description

Image description

  • Build the Jenkins Pipeline

Image description

Image description

  • SonarQube report for code analysis

Image description

  • Docker registry where the image generated has been pushed

Image description

Image description

  • Update the docker image name in the deployment yml

Image description

  • Create a yml file in your local machine and apply this content to install ArgoCD controller

Image description

Image description

  • Make sure the argocd operator pods are created in MiniKube

Image description

  • Edit the service type from Cluster IP to NodePort for example-argocd-server

Image description

Image description

Image description

  • Get URL to access the service through web

Image description

  • Get the password to argocd account by getting into argocd-cluster secret

Image description

  • Decode your base 64 encrypted secret

Image description

  • Enter the credentials in ArgoCD web interface

Image description

Image description

  • Create application in argocd and configure required information

Image description

Image description

Image description

Image description

  • The spring boot application has been deployed in our minikube cluster through argocd

Image description

  • Edit the deployment image to nginx in the minikube

Image description

Image description

  • ArgoCD recognize that the image in manifest yml is different from the image executing on minikube cluster it starts to rollback to image mentioned in the manifest

Image description

Image description

Top comments (0)