Jenkins can be used for multiple purposes like whenever any developer commits any code changes to SCM, Jenkins triggers job which can Checkout the code, build it, run JUnit test case, run tools like sonar or checkmarx and if everything works properly then deploy it to some instance.
In this tutorial, I’ll share my knowledge on how can we automate our test process by introducing CI like Jenkins. We will configure Jenkins such that it should trigger it whenever any code commits by any developer to SCM, pull out the code from GIT, run maven to build and test the code.
Once your Jenkins is up and running then you will see below screen
· Install the required plugin.
o Make sure all the required plugins like GIT, Maven are already present
o Goto Manage Jenkins -> manage plugins -> Installed tab
o In case, if you don’t find the required plugin then search under the Available tab. E.g. to install the Maven Integration plugin.
o Select plugin and click on Download now and install after restart.
o It will take some time to download and install the plugin as per your network bandwidth.
Set Java and Maven Path
o by default, Jenkins pick up the JAVA and Maven path running on Ubuntu instance but if you have any specific java or maven directory then you can configure those as well.
o Goto Manage Jenkins -> Global tool configuration
Generate SSH keygen for Jenkins user
o If you want to access a private Git repo, for example at GitHub, you need to generate an ssh key-pair. Create a SSH key with the following command.
o The public-key must be uploaded to the service you are using, e.g., GitHub.
· Setting up Jenkins job
o The build of a project is handled via jobs in Jenkins. Click New Item. Afterward, enter a name for the job and select the Freestyle Project and press OK.
o Add description of the job
o Check Discard old builds. It will help you in cleaning the stale log. You can choose the log rotation based on the number of builds or days. Always enable and choose this option to make sure you are not running out of memory of Jenkins log.
o Under Source code Management choose Git as we are going to checkout the code from GIT.SET git url (https://github.com/abdulwaheed18/demo.git) and no need of credential as my repo is public and set branch as master.
o Under Build triggers, choose poll SCM so that it should run this job whenever someone commit the code to the master branch.
o Schedule value in * which defines the time.
o Which means pull the SCM every day of every month and every minute of every hour.
o Select top-level maven targets under Build and set Goals as clean package.
o Apply and save the configuration.
· Run the build
o Job is created as jenkins-demo.
o Click on jenkins-demo and then Build now to run the newly created job.
· Congratulation! Your first job is created successfully and the blue circle under Build history means there was no issue during job execution and it ran successfully.
Post a Comment