In this project, we will configure a Jenkins build pipeline to build, compile, and package a small java project. The Jenkins pipeline is designed in such a way that whenever a change is pushed from the local repository to the Git repository, Jenkins will detect the change and will automatically start to build the project.
1. Create a sample java program and push it to your Git repository
- Firstly, as prerequisites setup git in your local machine and create a GitHub repository.
- Now, you can create any sample program. I have created a sample java program that prints "Jenkins integration with Git".
- Now, push your code to the remote Git repository.
2. Start your Jenkins Server and install Git
Install and setup Jenkins server on Amazon Ec2 instance or your local machine.
[Refer my previous video – Installation of Jenkins]Next, connect through SSH to your previously created Jenkins instance and start your Jenkins server
sudo service jenkins start
- Run the following commands to install git.
sudo yum install git -y
git version
Access the Jenkins server using the public DNS of the EC2 instance or public IP of the instance on port 8080.
http://{ec2-public-dns}:8080 or http://{public IP}:8080/Login to Jenkins console using your credentials.
3. Add Git plugins in Jenkins
Now, we will install the required plugins for our project.
- In your Jenkins console, go via the Jenkins GUI -> Manage Jenkins -> Manage Plugins.
- Select the tab “Available” and select all the Git plugins and then click on Install without Restart. Mine are already installed.
- This step is the most important one as it will allow us to access the code from our git repository. Installation of plugins might take a few minutes.
4. Create a Jenkins Job
Let’s now create our pipeline for this project. After the installation of plugins, return to the Dashboard.
- Via Jenkins -> New Item you’ll get to a page that will let you specify which kind of job you want to create.
- For now, start by creating a Freestyle Project, give a project name, and hit OK.
5. Configure Jenkins job to trigger the pipeline, after each change/commit is pushed to your Git repository
- To configure the pipeline, select the GitHub Project option and add your GitHub repository URL.
- In Source Code Management select Git and add your Git repository URL.
- This will allow Jenkins to access the source code from the git repository.
For more reference
Top comments (0)