Jenkins Continuous Integration Pipeline Using AWS EC2 Instances
Developer job is to write/change the code test locally if they are good with the changes then they push it to the central repository like github , developer will have a git tool which will be integrated with github whenever any change occur in the code at central repo jenkins will detect and fetch the code using git tool and git plugin after that code will be build using maven tool once build complete it will generate artifacts, next we will conduct unit test again by using maven once your unit test reports ready you will conduct another test called code analysis, unit test checks whether the unit of code works while code analysis checks if the code has any vulnerability, are you following best practise, any bugs sonarQube scanner can be use for it this generates reports in xml format and these report will be uploaded on sonarqube server. We can also set quality gate at sonarqube server to check the quality of code else fails the build and pipeline stops. It it passes the gate then we will have verified copy of artifact. Before uploading this artifact on the server this artifact will be versioned NexusSonatype repository.
First launch EC2 instance for jenkins server with ubuntu 20 and use jenkins server script in userdata section while creating the instance:
Nexus:
This is a declarative way of pipeline not scriptive.
Now save it and and define jdk8 and maven tools in manage jenkins → tools configuration option:
Maven will be install automatically but for jdk install it manually on ec2 instance and define its path in jenkins as mentioned below:
⇒ sudo apt update
⇒ sudo apt install openjdk-8-jdk
Also add maven tool:
Now we will see how can we scan the code with sonar scanner and upload on the sonarqube server through pipeline as a code:
In next stage we will not only do sonar analysis, but all the reports like checkstyle report, unit test report , basically in short in this stage sonarqube will scans all the reports and upload on the sonarqube server:
Now quality gate will pass the code , and our next step will be upload artifacts in nexus repository:
Click on create repository and choose maven(hosted) because our goal is to store artifacts if our goal would be download dependencies from the repositories then choose maven(proxy).
And maven(group) is use to group repo together:
copy the tokean and domain name that will put in jenkins in workspacne name then save it.
Thats all in this project.