In the previous article, we installed Jenkins on a Linux server as a Docker container. And now it is time to put our Jenkins server into use. In this article, we are going to look into configuring a very simple freestyle job in Jenkins.
What is a Freestyle Job in Jenkins?
A freestyle job in Jenkins supports simple continuous integration by allowing you to run certain tasks in application lifecycle in sequence. It offers plugins to help with the build steps.
However, capabilities of freestyle jobs are limited, but it is a good starting point to get acquainted with Jenkins as it is very easy to setup.
For the purpose of this article, I am going to build a simple Spring Boot project using Maven.
Step 1: Add Build Tools
First thing we need to do is adding the build tools that we need. In this case, it is Maven.
In Jenkins dashboard, go to “Manage Jenkins” and then click on “Global Tool Configuration” as shown below.
In global tool configuration, scroll down to the Maven section and click on “Add Maven” button. Specify a name and the version you need and save.
Now that is over with, we can create our freestyle job.
Step 2: Create the Freestyle Job
To create a job, in Jenkins dashboard, click on “New Item”.
This will bring you to below screen. Select “Freestyle project” and specify a name for your job. Then press OK.
Once you press OK, it brings you to the configuration page of the job.
Step 3: Add a Git Repository to the Job
In order to build our project, first we have to fetch it from our Git repository. If you don’t have your own project, you can use my simple Spring Boot project in this link. You can specify the repository URL and credentials as below.
To add credentials of the repository, click on the “Add” button and select “Jenkins”. This will open a dialog window as below.
Here, “kind” should be Username with password as we have specified the https URL for GitHub repository URL. Once all the details are filled in, click “Save”, which will close this dialog window.
As the branch to build, we are going to give the master branch, which is the default value.
Once all the details are filled in, scroll down to “Build” section.
Step 4: Add Build Step
In build section, from “Add build step” drop down, select “Invoke top-level Maven targets” as below.
Then you can specify the -Dmaven.test.skip=true clean package
command as below. Note that mvn
prefix is not included in the command. You should also select the correct version of Maven from the drop down, which is the version we added in step 1.
Once this is done, you can save and we are ready to build!
Step 5: Build the Project
Now all that’s left to do is to build our project. You can click “Build now” from the job to do this.
Once you click “Build Now”, under build history, you can see the first build is in progress. If you click on the timestamp link, you can see the console output as below.
As you can see, our first job is a success! If there were any errors, we would be able to see it here and we can correct them and re-do the build if necessary.
In the next article, we will look into how to build a Docker image for our project and and push the image to our Docker Hub repository.