Your First Jenkins Job: Freestyle Project, Build Steps, Console Output and Post-Build Actions

CI CD Pipelines with Jenkins 30 min min read Updated: Nov 17, 2026 Beginner
Your First Jenkins Job: Freestyle Project, Build Steps, Console Output and Post-Build Actions
Beginner Topic 3 of 3

Create the Job

  1. Dashboard, New Item
  2. Name: hello-jenkins, choose Freestyle project, click OK
  3. Under Build Steps, *Add build step*, *Execute shell* (Windows agents: *Execute Windows batch command*)
  4. Paste the script below, Save
  5. Click Build Now, then open build #1 and Console Output
bash echo "Hello from Jenkins" echo "Build number: $BUILD_NUMBER" echo "Job name: $JOB_NAME" echo "Workspace: $WORKSPACE" date whoami uname -a

Read the Console Output

Result

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

  • -xe means every command is printed (-x) and the script stops at the first failure (-e)
  • The last line shows the result: Finished: SUCCESS or FAILURE
  • A step fails when its exit code is not 0
Try a failure: Add the line exit 1 and build again. The job turns red. Remove it to go back to blue or green.

Built-in Environment Variables

VariableMeaning
BUILD_NUMBERNumber of this build
BUILD_ID, BUILD_URLID and link to this build
JOB_NAMEName of the job
WORKSPACEFolder where the job runs
JENKINS_URLBase URL of the server
NODE_NAMEWhich agent runs it
GIT_COMMIT, GIT_BRANCHSet 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:

bash echo "Deploying to $TARGET with colour $COLOR"

Now Build Now becomes Build with Parameters and shows a form.

Parameter typeUse
String, TextFree text
BooleanYes or no switch
ChoicePick from a list
PasswordA secret value (masked)
FileUpload a file for the build
Git Parameter (plugin)Pick a branch or tag

Check Out Code From Git

  1. In the job, under Source Code Management, choose Git
  2. Repository URL: https://github.com/your-user/your-repo.git
  3. For a private repository add Credentials (stored in Jenkins, see the credentials lesson)
  4. Branch Specifier: */main
  5. Add a build step that uses the code, for example ls -la and ./build.sh
bash ls -la git log -1 --oneline chmod +x build.sh && ./build.sh

The code appears in the Workspace. Open it from the job page to see the files.

Post-Build Actions

ActionPurpose
Archive the artifactsSave files such as target/*.jar so you can download them from the build page. Pattern example: target/*.jar
Publish JUnit test result reportRead test XML files like target/surefire-reports/*.xml and show trends and failures
Build other projectsStart a downstream job after this one succeeds
E-mail NotificationSend mail when the build fails or recovers (needs SMTP set in system settings)
Delete workspace when build is doneKeep 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 jobPipeline
Configured by clicking in the UIConfigured by code in a Jenkinsfile stored in Git
Hard to review, copy or versionReviewed, versioned and reusable like any code
Simple, linear stepsStages, parallel work, conditions, retries, approvals
Good for learning and tiny tasksThe 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

  1. Create the hello job and break it on purpose with exit 1
  2. Add a parameter and print it
  3. Check out a small public repository and run a command from it
  4. Archive a file you create, such as report.txt, and download it from the build page
  5. 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.

Quick Summary: New Item freestyle; execute shell; console + exit codes; env vars; parameters; Git SCM; archive/JUnit/email; discard old builds; freestyle vs pipeline.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators