How to create a freestyle project (Job)
What is a freestyle job/project?

A freestyle project is a simple build job or task. This task can be running some commands, building code, testing source code, deploying code on some other server, and much more. The freestyle project is the most configurable and flexible option and the setup is quite easy. It provides the UI option to configure steps which makes it easy to work with.

The freestyle job has limited actions like build and post-build steps. This limitation is solved in Jenkins by the use of plugins.

Creating a freestyle job.

In this example, we are going to create a freestyle job that will run some simple Linux commands.

Step 1. Login in Jenkins

First, you need to login into Jenkins with the credentials that you have used while installing Jenkins.

jenkins_login

Step 2. Create a New Item

Click on the “New Item” at the top left of the Jenkins dashboard.

new-project

Step 3. Provide Item details

✔ Enter the name of the project.

✔ Choose Freestyle Project.

✔ Click Ok at the bottom

freestyle-project-create

Step 4. Enter the Project Details

Enter some description about the project.

job-description

Step 5. Adding a build step

Under build

✔  Click on Add build step.

✔  Choose Execute shell

build-step-option

✔ Write some Linux commands. For ex. pwd and whoami

build-step

Step 6. Save the project.

Click on Apply and then Save.

Step 7. Build the Project

Now, click on Build Now to build the project.

build-button

Step 8. Check the Output and Status

Click on the build number and then click on Console Output and you will able to see the logs and build status.

build-history

console-output

Conclusion:

We have created a simple freestyle project that performs Linux commands. A freestyle project can do much more, from running simple commands to deploying the build to a server.

Assignment:

✔  Create a freestyle project which takes the absolute path of a directory as input,

✔  able to list all files and folders inside that,

✔  prints “directory does not exist” if the directory is not present there,

✔  prints “Not allowed” if you don’t have permission to list the files.

✔  And able to list only the last 10 builds of the last 2 days in “Build History”.