Goal
By the end of this lab, you will understand:
Jenkins → Job → Build → Console Output → Workspace
You will create a job that Jenkins executes automatically.
Prerequisites
Make sure Jenkins is running. On your Mac, you can check:
brew services list | grep jenkins
If Jenkins is stopped:
brew services start jenkins-lts
Then open:
http://localhost:8080
You should see the Jenkins Dashboard.
Step 1 — Create Your First Job
On the Jenkins Dashboard:
New Item → Enter a name:
my-first-job
Choose:
Freestyle project
Click:
OK
What is a Jenkins Job?
A job is a task that Jenkins knows how to execute.
For example, later your jobs can:
Pull code from GitHub
↓
Run tests
↓
Run security scan
↓
Build Docker image
↓
Push image to ECR
↓
Deploy to Kubernetes
But today we'll start with a simple command.
Step 2 — Add Your First Build Step
Scroll down to:
Build → Add build step → Execute shell
Paste:
echo "Hello from Jenkins!"
echo "This is my first Jenkins job."
echo "Jenkins is running commands automatically."
Click:
Save
You should now be on the job page.
Step 3 — Run the Job
Click:
Build Now
On the left side you should see:
Build History
#1
Click:
#1
Then click:
Console Output
Expected output:
Started by user
Building in workspace ...
Hello from Jenkins!
This is my first Jenkins job.
Jenkins is running commands automatically.
Finished: SUCCESS
If you see:
Finished: SUCCESS
your first Jenkins job worked.
Step 4 — Understand What Just Happened
You manually clicked:
Build Now
Jenkins then:
1. Created a build
↓
2. Created/used a workspace
↓
3. Started a shell
↓
4. Executed your commands
↓
5. Collected the output
↓
6. Determined SUCCESS/FAILURE
This is the foundation of CI/CD.
Step 5 — Make the Job More Useful
Go to:
my-first-job → Configure
Replace the shell commands with:
echo "================================"
echo " JENKINS DEVOPS LAB"
echo "================================"
echo ""
echo "Current user:"
whoami
echo ""
echo "Current directory:"
pwd
echo ""
echo "Files:"
ls -la
echo ""
echo "Git version:"
git --version
echo ""
echo "Java version:"
java -version
echo ""
echo "Current date:"
date
echo ""
echo "================================"
echo "BUILD COMPLETED"
echo "================================"
Save it.
Click:
Build Now
Then open:
Build History → #2 → Console Output
You should see information about the Jenkins environment.
Step 6 — Understand the Jenkins Workspace
One very important DevOps concept is the workspace.
When Jenkins runs a job, it needs a directory in which to work.
Your command:
pwd
may show something similar to:
/Users/Shared/Jenkins/Home/workspace/my-first-job
or another Jenkins workspace location depending on your installation.
Think of it as:
Jenkins
│
└── workspace
│
└── my-first-job
│
├── source code
├── build files
├── test files
└── generated artifacts
Later, when Jenkins clones a GitHub repository, the repository will normally appear in this workspace.
Step 7 — Learn SUCCESS vs FAILURE
Now let's intentionally break the build.
Go to:
my-first-job → Configure → Build → Execute shell
Use:
echo "Starting application deployment..."
echo "Checking application..."
exit 1
echo "Deployment completed."
Save and click:
Build Now
Open:
#3 → Console Output
You should get:
Finished: FAILURE
Why?
Because:
exit 1
means the command failed.
In Linux:
exit 0 = SUCCESS
exit 1+ = FAILURE
This concept is extremely important for CI/CD.
For example:
Jenkins
↓
Run tests
↓
Tests return exit 0
↓
Continue deployment
But:
Jenkins
↓
Run tests
↓
Tests return exit 1
↓
STOP
↓
Build FAILED
This prevents bad code from reaching production.
Step 8 — Fix the Build
Go back to Configure and replace the script with:
echo "Starting Jenkins build..."
echo "Checking Git..."
git --version
echo "Checking Java..."
java -version
echo "Running application test..."
echo "Test passed!"
echo "Build completed successfully."
exit 0
Run another build.
Expected result:
Finished: SUCCESS
Step 9 — Create a Small Project
Now let's make the lab closer to real DevOps work.
On your Mac Terminal:
mkdir jenkins-first-project
cd jenkins-first-project
Create a file:
touch app.sh
Open it:
nano app.sh
Paste:
#!/bin/bash
echo "================================"
echo "My Application"
echo "================================"
echo "Application started successfully!"
echo "Environment: Development"
echo "Version: 1.0.0"
Save with:
CTRL + O
ENTER
CTRL + X
Give it permission:
chmod +x app.sh
Run:
./app.sh
Expected:
================================
My Application
================================
Application started successfully!
Environment: Development
Version: 1.0.0
Step 10 — Put It on GitHub
Initialize Git:
git init
git add .
git commit -m "Initial Jenkins lab"
Create a GitHub repository called:
jenkins-first-project
Then connect your local project to it:
git branch -M main
git remote add origin YOUR_GITHUB_REPOSITORY_URL
git push -u origin main
Now you have:
Developer
↓
GitHub
↓
jenkins-first-project
Step 11 — Connect Jenkins to GitHub
Go back to Jenkins.
Create another job:
New Item
Name:
jenkins-github-job
Choose:
Freestyle project
Click OK.
Under:
Source Code Management
select:
Git
Repository URL:
YOUR_GITHUB_REPOSITORY_URL
For a public repository, credentials aren't necessary.
Set branch to:
*/main
Step 12 — Tell Jenkins What to Run
Go to:
Build → Add build step → Execute shell
Paste:
echo "================================"
echo "JENKINS CI BUILD STARTED"
echo "================================"
echo ""
echo "Workspace:"
pwd
echo ""
echo "Source code:"
ls -la
echo ""
echo "Running application..."
chmod +x app.sh
./app.sh
echo ""
echo "================================"
echo "BUILD SUCCESSFUL"
echo "================================"
Save.
Click:
Build Now
Open:
Build History
→ #1
→ Console Output
You should see Jenkins clone your GitHub repository and execute app.sh.
What You Built
Your architecture is now:
┌──────────────┐
│ Developer │
│ Mac │
└──────┬───────┘
│
│ git push
▼
┌──────────────┐
│ GitHub │
│ Repository │
└──────┬───────┘
│
│ git clone / checkout
▼
┌──────────────┐
│ Jenkins │
│ Job │
└──────┬───────┘
│
│ Execute shell
▼
┌──────────────┐
│ app.sh │
└──────┬───────┘
│
▼
SUCCESS
What your students should understand after Lab 1
They should be able to explain these concepts:
| Concept | Meaning |
|---|---|
| Jenkins | Automation server |
| Job | Task Jenkins executes |
| Build | One execution of a job |
| Workspace | Directory where Jenkins works |
| Console Output | Logs from the build |
| Execute Shell | Run Linux/macOS commands |
| Exit 0 | Success |
| Exit 1 | Failure |
| Git | Source-code version control |
| GitHub | Remote repository |
| CI | Automatically build/test code changes |
The most important takeaway is:
Jenkins takes work that a DevOps engineer could perform manually and executes it in a repeatable, automated way.
For your next lab, I recommend moving directly to Pipeline Job + first Jenkinsfile. That is where students start learning Jenkins the way it's commonly used in DevOps: GitHub → Jenkinsfile → stages → build → test → deploy.
Top comments (0)