Create the Job
- Dashboard, New Item
- Name:
hello-jenkins, choose Freestyle project, click OK - Under Build Steps, *Add build step*, *Execute shell* (Windows agents: *Execute Windows batch command*)
- Paste the script below, Save
- Click Build Now, then open build #1 and Console Output
Read the Console Output
Started by user admin Running as SYSTEM Building in workspace /var/lib/jenkins/workspace/hello-jenkins [hello-jenkins] $ /bin/sh -xe /tmp/jenkins123.sh + echo Hello from Jenkins Hello from Jenkins Finished: SUCCESS
-xemeans every command is printed (-x) and the script stops at the first failure (-e)- The last line shows the result:
Finished: SUCCESSorFAILURE - A step fails when its exit code is not 0
exit 1 and build again. The job turns red. Remove it to go back to blue or green.
Built-in Environment Variables
| Variable | Meaning |
|---|---|
BUILD_NUMBER | Number of this build |
BUILD_ID, BUILD_URL | ID and link to this build |
JOB_NAME | Name of the job |
WORKSPACE | Folder where the job runs |
JENKINS_URL | Base URL of the server |
NODE_NAME | Which agent runs it |
GIT_COMMIT, GIT_BRANCH | Set after a Git checkout |
BUILD_USER (plugin) | Who started the build |
See the full list at JENKINS_URL/env-vars.html.
Add Parameters
Tick This project is parameterized and add a String parameter TARGET with default dev, and a Choice parameter COLOR with red, green, blue. Then use them in the shell step:
Now Build Now becomes Build with Parameters and shows a form.
| Parameter type | Use |
|---|---|
| String, Text | Free text |
| Boolean | Yes or no switch |
| Choice | Pick from a list |
| Password | A secret value (masked) |
| File | Upload a file for the build |
| Git Parameter (plugin) | Pick a branch or tag |
Check Out Code From Git
- In the job, under Source Code Management, choose Git
- Repository URL:
https://github.com/your-user/your-repo.git - For a private repository add Credentials (stored in Jenkins, see the credentials lesson)
- Branch Specifier:
*/main - Add a build step that uses the code, for example
ls -laand./build.sh
The code appears in the Workspace. Open it from the job page to see the files.
Post-Build Actions
| Action | Purpose |
|---|---|
| Archive the artifacts | Save files such as target/*.jar so you can download them from the build page. Pattern example: target/*.jar |
| Publish JUnit test result report | Read test XML files like target/surefire-reports/*.xml and show trends and failures |
| Build other projects | Start a downstream job after this one succeeds |
| E-mail Notification | Send mail when the build fails or recovers (needs SMTP set in system settings) |
| Delete workspace when build is done | Keep disks clean |
Build History and Housekeeping
- Each build keeps its log, artifacts and test results. Over time the disk fills
- Tick Discard old builds and keep for example the last 20 builds or 14 days
- Use Delete workspace options on busy agents
- Use the Build Queue and Build Executor Status panels to see what waits and what runs
Freestyle or Pipeline?
| Freestyle job | Pipeline |
|---|---|
| Configured by clicking in the UI | Configured by code in a Jenkinsfile stored in Git |
| Hard to review, copy or version | Reviewed, versioned and reusable like any code |
| Simple, linear steps | Stages, parallel work, conditions, retries, approvals |
| Good for learning and tiny tasks | The standard for real CI/CD |
Learn freestyle first to understand the pieces. From the next sections on, you will build pipelines for everything important.
Practice Tasks
- Create the hello job and break it on purpose with
exit 1 - Add a parameter and print it
- Check out a small public repository and run a command from it
- Archive a file you create, such as
report.txt, and download it from the build page - Set a limit on build history
Conclusion
A freestyle job runs shell steps on an agent, shows the output in the console, and can take parameters, check out Git and run post-build actions such as archiving and test reports. Steps fail on a non-zero exit code. Freestyle is good for learning; real CI/CD uses pipelines.

