How to Create a Freestyle Project in Jenkins

How to Create a Freestyle Project in Jenkins

Before I ever wrote a Jenkinsfile, I started with Freestyle projects — Jenkins’ original, GUI-driven way of defining a job. Even though Pipelines have become the modern standard, Freestyle projects are still incredibly useful for simple tasks, quick automation, and for anyone just getting started with Jenkins. In this guide, I’ll walk through exactly how to create one, configure it properly, and use it effectively.

What Is a Freestyle Project?

A Freestyle project is Jenkins’ simplest job type. Instead of writing pipeline code, you configure everything — source code checkout, build steps, post-build actions — through a web form in the Jenkins UI. It’s straightforward, visual, and doesn’t require learning Groovy syntax, which makes it a great entry point for beginners.

Jenkins Architecture Recap

Regardless of job type, Jenkins always follows the same controller-agent model. When you create a Freestyle project, you’re essentially defining a job configuration that the controller stores, and when triggered, dispatches to an agent (or itself, if no agents are configured) for execution.

Step 1: Access the Jenkins Dashboard

Log into your Jenkins instance and, from the main dashboard, click “New Item” in the left sidebar.

Step 2: Name Your Project and Select Freestyle

Enter a name for your job (avoid spaces — use hyphens or underscores instead, e.g., my-first-freestyle-job). Select “Freestyle project” from the list of job types, then click OK.

Step 3: General Configuration

At the top of the configuration page, you can:

Example of adding a parameter:

Step 4: Source Code Management

Under this section, choose Git (assuming your code lives in a Git repository) and provide:

If your project doesn’t use version control at all, you can leave this as “None,” though I’d strongly recommend using Git for virtually any real project.

Step 5: Build Triggers

This section defines what causes the job to run:

For a simple learning project, “Build periodically” or manual triggering (leaving this section empty and clicking “Build Now”) both work fine.

Step 6: Build Environment

Here you can configure options like:

Step 7: Build Steps

This is where the actual work happens. Click “Add build step” and choose from options like:

Example shell build step:

echo "Starting build for environment: $ENVIRONMENT"
npm install
npm run build
npm test

You can chain multiple build steps, and Jenkins executes them sequentially, stopping if any step returns a non-zero exit code (unless configured otherwise).

Step 8: Post-build Actions

After the build steps run, you can configure:

Example artifact archiving pattern: build/**/*.jar or dist/**.

Step 9: Save and Run

Click Save, then click “Build Now” from the job’s page to trigger your first build manually. You’ll see the build appear in the Build History panel; click it to view the Console Output and watch your build steps execute in real time.

Freestyle vs Pipeline: When to Use Which

I generally recommend Freestyle projects for:

And Pipeline (Jenkinsfile-based) projects for:

That said, Freestyle projects remain fully supported and are still widely used for simpler automation needs.

Real-World Example: A Simple Notification Job

Here’s a practical Freestyle project I’ve set up before — a job that checks a website’s uptime and sends a Slack alert if it’s down:

Build Trigger: Build periodically — H/10 * * * * (every 10 minutes)

Build Step (Execute shell):

STATUS=$(curl -o /dev/null -s -w "%{http_code}\n" https://yourapp.com)
if [ "$STATUS" -ne 200 ]; then
  echo "Site down! Status: $STATUS"
  exit 1
fi
echo "Site is up. Status: $STATUS"

Post-build Action: Slack Notifications plugin configured to alert on failure.

Using the “Execute Windows Batch Command” Build Step

If your Freestyle project runs on a Windows agent, you’ll use “Execute Windows batch command” instead of “Execute shell.” The syntax follows standard Windows batch/CMD conventions:

echo Starting build for environment: %ENVIRONMENT%
dotnet restore
dotnet build --configuration Release

Parameters defined earlier (like ENVIRONMENT) are automatically exposed as environment variables, accessible with %PARAM_NAME% syntax on Windows or $PARAM_NAME on Linux/macOS.

Combining Multiple SCM Sources

Occasionally a Freestyle job needs to pull code from more than one repository — for example, your application code plus a shared configuration repository. Jenkins supports this through the “Multiple SCMs” option (via the Multiple SCMs Plugin), letting you check out several repositories into different subdirectories of the same workspace before running your build steps.

Adding Conditional Build Steps

For more advanced Freestyle configurations, the “Conditional BuildStep” plugin lets you run certain steps only if specific conditions are met — for instance, only running a deployment step if a particular parameter equals production, all through the UI without writing any Groovy.

Troubleshooting Common Freestyle Project Issues

Archiving Build History for Auditing

For teams in regulated industries, keeping a longer build history for audit purposes is often required. Rather than the default “Discard old builds” policy, you can configure a longer retention window or export build logs to external long-term storage using a post-build step that copies console output and artifacts to an archive location outside Jenkins itself.

Security Best Practices

FAQs

Q: Can a Freestyle project use a Jenkinsfile? No — Freestyle projects are configured entirely through the UI. If you want your build logic in a Jenkinsfile, you need to create a Pipeline job instead.

Q: Can I convert a Freestyle project to a Pipeline later? There’s no automatic converter, but it’s usually straightforward to manually translate your build steps and post-build actions into an equivalent Jenkinsfile.

Q: Are Freestyle projects deprecated? No, they’re still fully supported and commonly used, especially for simpler automation tasks, though Pipelines are generally recommended for anything nontrivial.

Q: Can Freestyle projects run on specific agents only? Yes — check “Restrict where this project can be run” and specify a label matching the desired agent(s).

Summary

Freestyle projects are Jenkins’ original, form-based way of defining automation jobs, and they’re still a great option for simple builds, scheduled tasks, and anyone new to Jenkins. By walking through source code management, build triggers, build steps, and post-build actions, you can have a working automated job in just a few minutes — no scripting required.

References

Exit mobile version