How to create CI builds with the Jenkins freestyle project
If your team installs Jenkins, they have to decide which plug-ins they'll use. Among the many options are Maven, Git, OAuth, Pipeline and even Green Balls for those users who aren't fans of the blue indicator for a successful build. However, teams just getting started with Jenkins should eschew all of those options. To learn Jenkins, start off with a basic, vanilla installation without a plethora of optional plugins that act as distractions.
How to become a Jenkins expert
Step1 -- Getting started with Jenkins
Step 2 -- Create a simple Jenkins freestyle job
Step 3 -- Inject Jenkins environment variables into your builds
Step 4 -- Fix any Jenkins plugin download errors
Without any other plug-ins installed, the only type of Jenkins item a user can create is a Jenkins freestyle project. Additionally, the only type of build job available is a Jenkins freestyle job. This approach is the best way to learn Jenkins' fundamentals and how continuous integration (CI) works. Accordingly, the focus of this video tutorial is to create a Jenkins freestyle project and run a Jenkins freestyle job.
What is a Jenkins freestyle project?
A Jenkins project is simply a repeatable build job that can contain steps and post-build actions. The options for what you can do in a build step or post-build action are limited, without plug-ins. Standard options are available within a Jenkins freestyle project, and include the ability to configure build triggers, enable project-based security and parameterize the Jenkins project. To do anything specialized or atypical without plug-ins, the user must run a Unix shell script or a Windows batch command.
When to use a Jenkins freestyle project
Access to the shell or batch environment creates a high level of security access for the Jenkins freestyle project. In these environments, it's easy to create a script that instructs a Jenkins freestyle job to FTP a file from one server to another, compile a director of Java code or even run a SonarQube test. A Jenkins freestyle job can be as powerful and complex as any build job created with a Jenkins pipeline or a Groovy DSL. The only downside to freestyle projects is that the user must know how to script all of these actions and, more importantly, other developers need to understand how to maintain these scripts.
Plug-ins are the recommended way to access resources such as Git, Maven and SonarQube. Technologically, there is nothing to stop a developer from writing a script to access those resources within a Jenkins freestyle project. However, the development team should follow security best practices and prohibit a scripted approach.
A simple Jenkins freestyle job
This Jenkins tutorial uses a Windows machine, so the Jenkins freestyle job will execute a batch command as part of the CI build step. That batch command is simple and does nothing more than invoke the version flag on the Java installation. It prints out to Jenkins' console logs information which version of the Java Development Kit (JDK) the Jenkins freestyle job uses. This simple script demonstrates how a Jenkins build job can access the underlying OS. There is also a call to list the current directory that the Jenkins freestyle job uses as its local workspace. The batch command looks like this:
java -version
dir
For the full build job tutorial and to create a Jenkins freestyle job from start to finish, watch the video. Then, try to recreate the steps on your own. This exercise will give you a solid understanding of when to use a Jenkins freestyle project and how to run the freestyle job.
Check out our video on JDK download and JRE installation.