In this article we are going to cover Build Java Project using Gradle Jenkins Freestyle Job, Configure Gradle in Jenkins, Create a New Freestyle Job, Configure Source Code Management, Configure the Build steps, Configure Post-Build Actions, Monitor Build Progress.
Why we use is Jenkins?
Jenkins is used to automate and streamline software development processes. It integrates with version control systems, automates building, testing, and deployment, ensuring code quality, reducing manual errors, and accelerating development cycles. Jenkins enhances collaboration, provides real-time insights, and supports continuous integration and delivery practices.
What is Gradle?
Gradle is an open-source build automation tool that is primarily used for building, automating, and managing the build process of software projects. It is often used for Java, Groovy, and Kotlin projects but is adaptable for other languages and platforms as well. Gradle offers a powerful and flexible build system that is designed to handle complex project dependencies and build workflows.
What is purpose of Building Java Project using Gradle Jenkins Freestyle Job?
The purpose of building a Java project using a Gradle Jenkins Freestyle Job is to automate and standardize the process of compiling, testing, and packaging a Java application within the Jenkins continuous integration environment, ensuring code quality and facilitating efficient software development and deployment.
The process of setting up a Jenkins Freestyle Job to build a Java project using Gradle. Before you proceed, make sure you have the following prerequisites:
- Jenkins Installed: You need Jenkins installed on your server.
- Gradle Installed: Gradle needs to be installed on the machine where Jenkins is running.
- A Java project with Gradlehosted in a version control system like Git.
Assuming Jenkins and Gradle are properly installed, follow these steps to create a Jenkins Freestyle Job for building a Java project using Gradle:
How to Build Java Project using Gradle Jenkins Freestyle Job?
Step #1:Log in to your Jenkins server.
Step #2:Configure Gradle in Jenkins:
- Install Plugins (if necessary): If you haven’t done so already, you might need to install plugins like Gradle Plugin and Git Plugin from the Jenkins Plugin Manager.
Navigate to Dashboard->> Manage Jenkins ->> Manage Plugin
Now search for “Gradle Plugin” and “Git plugin” and click on checkbox after that click on Download now and install after restart.
- Configure Gradle in Global Tool Configuration:
Go to Jenkins dashboard and Click on Manage Jenkins > Tool Configuration.
Find the section for Gradle and click on Add Gradle.
Provide a name for the Gradle installation, and specify the Gradle distribution URL or choose to install automatically from the internet.
Step #3:Create a New Freestyle Job:
- Create a New Job: Click on New Item on the Jenkins dashboard.
Enter a name for your job, select Freestyle project, and click OK.
Step #4:Configure Source Code Management:
- In the job configuration, find the Source Code Management section.
- Choose your version control system (e.g., Git) and provide the repository URL.
Step #5:Build Step Configuration
Scroll down to the Build section and Click on Add build step and choose Invoke Gradle script and also select “Execute shell” (or “Execute Windows batch command” if you are on Windows).
Configure Gradle Build: Select the Gradle version you configured in the Global Tool Configuration. In the Tasks field, specify the Gradle tasks you want to execute (e.g., clean build).
Configure execute windows batch command: In the shell command text box, you will specify the Gradle build commands. For example, if your Java project has a build.gradle file in its root directory, you can use the following commands:
# Run Gradle build
gradle clean build
some other command you can also run like below command:-
cd C:\ProgramData\Jenkins\.jenkins\workspace\java gradle project
For BUILD_ID :-
For BUILD_DISPLAY_NAME :-
For JOB_NAME :-
For GIT_URL :-
Step #6:Post-Build Actions (Optional):
You can configure post-build actions such as archiving artifacts, sending notifications, etc., based on your project requirements.
Configure E-mail Notification:
Step #7:Save and Build: Click on Save to save the job configuration.
Trigger the build manually by clicking on Build Now or wait for the job to be triggered based on your build triggers.
Step #8:Monitor Build Progress
View Console Output: Click on the build number in the “Build History” section to view the console output. You can monitor the progress and identify any issues during the build process.
Console output: Jenkins will execute the Gradle build commands specified in the build step, and you’ll be able to view the build output and logs within the Jenkins job’s console output.
That’s the detailed process for configuring a Jenkins Freestyle job to build a Java project using Gradle. You can customize it further based on your project’s specific requirements and incorporate it into your CI/CD pipeline as needed.
In this article we have covered Build Java Project using Gradle Jenkins Freestyle Job, Configure Gradle in Jenkins, Create a New Freestyle Job, Configure Source Code Management, Configure the Build steps, Configure Post-Build Actions, Monitor Build Progress.