Jenkins Freestyle Project: What It Is & How to Use It
A Jenkins freestyle project is the most basic and flexible job type in Jenkins, letting you build, test, and deploy software using simple, step-by-step configuration options rather than writing a pipeline script. You enter the project’s settings through the Jenkins web interface, point it at your source code, add build steps like shell commands or Windows batch scripts, and then trigger builds manually, on a schedule, or when code changes. This article explains how freestyle projects work, when to choose them over pipelines, and how to avoid common pitfalls.
What Is a Freestyle Project?
Freestyle is Jenkins’ original job type, introduced long before Declarative and Scripted Pipelines. It provides a graphical form where you configure:
- Source code management – Git, SVN, or other repositories.
- Build triggers – manual, scheduled (cron), or after a commit (webhooks/polling).
- Build environment – options like deleting the workspace before build, or setting timestamps.
- Build steps – execute shell, Windows batch, invoke Gradle, copy files, etc.
- Post-build actions – archive artifacts, publish test reports, send emails, or trigger other jobs.
Each build runs in a workspace directory on the Jenkins agent, and the results (success/failure, console output, artifacts) are stored and displayed in the Jenkins UI.
How a Freestyle Build Works
When you click “Build Now� or a trigger fires, Jenkins performs the following sequence:
- It checks out the source code into the workspace (if configured).
- It applies any build environment options (e.g., cleaning the workspace).
- It runs each build step in the order you defined them. A step that fails (non-zero exit code) stops the build and marks it as failed.
- It runs post-build actions, which may archive artifacts, publish reports, or notify users.
For example, a simple Java project might have a build step that runs mvn clean package. The console output shows the full log, and the resulting JAR can be archived as an artifact.
Freestyle vs. Pipeline: Which Should You Choose?
Pipelines (Declarative or Scripted) are now the recommended approach for complex or long-running workflows because they are version-controlled, support conditional logic, and are easier to maintain. However, freestyle projects are still useful for:
- Simple build jobs that only need a few steps.
- Users who prefer a GUI over writing code.
- Quick, ad-hoc tasks like running a script or copying files.
- Legacy jobs that have worked for years and don’t need changes.
If your build requires loops, try/catch, parallel branches, or input from a human, a pipeline is usually a better fit. Freestyle projects can’t easily express those without installing extra plugins and hacking shell scripts.
How to Create a Freestyle Project
Creating one is straightforward:
- From the Jenkins dashboard, click New Item.
- Enter a name and select Freestyle project.
- Under General, add a description and optionally restrict where it runs (label).
- Under Source Code Management, select Git (or another) and enter the repository URL and credentials.
- Under Build Triggers, choose how to start builds – e.g., “Poll SCM� with a cron schedule like
H/5 * * * *. - Under Build, click “Add build step� and pick “Execute shell� (Linux) or “Execute Windows batch command� (Windows).
- Enter your commands, e.g.,
makeorgradle build. - Under Post-build Actions, add actions like “Archive the artifacts� and specify
**/*.jar. - Click Save and then Build Now.
That’s it – you’ve created a working freestyle job.
Common Problems and How to Fix Them
Here are frequent issues users run into:
- Build fails with “command not found� – The PATH on the Jenkins agent may not include the tool (e.g., Maven). Use the full path or configure the tool in Jenkins global settings.
- Workspace not clean – Old files can interfere. Add a build environment option “Delete workspace before build starts� or manually run
cleanin your build tool. - Git clone fails due to credentials – Make sure you added the correct credentials in Jenkins and selected them in the SCM section.
- Build succeeds but no artifacts – Check that your artifact path pattern matches the files. For example,
target/*.jarnottarget. - Build hangs forever – A step might be waiting for input (e.g., a password prompt). Avoid interactive commands; use
yesor flags to suppress prompts.
Security and Best Practices
Freestyle projects run with the privileges of the Jenkins agent user, so a malicious build script could compromise the system. Follow these practices:
- Run agents with the least privilege needed – don’t use root or administrator.
- Use credentials stored in Jenkins, not plaintext in scripts.
- Restrict who can create and configure jobs using Jenkins’ matrix-based security.
- Keep the workspace and artifacts accessible only to the right people.
- Use the “Execute shell� step carefully – it runs on the agent, so any command is possible.
Also, be aware that freestyle projects don’t have built-in sandboxing; a pipeline with the Groovy sandbox offers some protection for untrusted code.
Alternatives to Freestyle Projects
If freestyle feels limiting, consider:
- Declarative Pipeline – A structured, code-first approach with a clear syntax and built-in features like stages and parallel execution.
- Scripted Pipeline – More flexible, using Groovy code for complex logic.
- Multibranch Pipeline – Automatically creates a pipeline for each branch in a repository.
- External tools – Some teams use standalone CI tools like GitLab CI or GitHub Actions, but those are outside Jenkins.
For new projects, Jenkins itself recommends pipelines. But freestyle projects remain a valid, simple solution for many use cases.
Frequently Asked Questions
Can I convert a freestyle project to a pipeline?
Yes, you can manually recreate the steps in a pipeline script. There’s also a plugin called “Pipeline: Job� that can help, but the easiest way is to write a Declarative Pipeline that mirrors your freestyle steps. You can’t automatically convert, but the logic is usually simple to transfer.
How do I pass parameters to a freestyle build?
Enable “This project is parameterized� in the General section, add string or choice parameters, and then reference them in build steps as environment variables like $PARAM_NAME (shell) or %PARAM_NAME% (Windows batch).
Why is my scheduled build not running?
Check that the cron expression is correct and that the Jenkins timezone is what you expect. Also, if you use “Poll SCM�, the build only runs when changes are detected – an empty poll won’t trigger a build. For a fixed schedule, use “Build periodically� instead.
Can I run a freestyle job on multiple agents?
Yes, if you don’t restrict it to a specific label, Jenkins will pick any available agent. To run on all agents simultaneously, you’d need a pipeline with parallel stages or a plugin like “Matrix Project�. Freestyle itself runs on one agent per build.
What is the difference between “Execute shell� and “Execute Windows batch command�?
They are the same concept but for different operating systems. “Execute shell� runs on Unix/Linux/macOS agents, while “Execute Windows batch command� runs on Windows. You can add both steps and use conditional logic, but a job will only run on agents that match the OS.
How do I archive multiple files?
In the “Archive the artifacts� post-build action, use a comma-separated list of patterns, e.g., **/*.jar, **/*.war. You can also use wildcards like **/build/libs/*.jar.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.