Jenkins Runs Commands For Me
Published: (February 5, 2026 at 07:06 PM EST)
2 min read
Source: Dev.to
Source: Dev.to
Before Jenkins
- Engineer runs commands manually
- Forgets steps
- Makes mistakes
- Cannot repeat reliably
With Jenkins
- Commands are written once
- Jenkins runs them the same way every time
- Anyone can click Build Now
🛠 Task Rules (IMPORTANT)
- ❌ No copy–paste
- ✅ Students type each line
- ✅ After each line, explain why it exists
🧩 Step 1: Create Freestyle Job
- Open Jenkins
- Click New Item
- Job name:
devops-first-script - Select Freestyle project
- Click OK
🧩 Step 2: Add Shell Build Step
- Scroll to Build
- Click Add build step
- Choose Execute shell
✍️ Step 3: Write This Script (Line by Line)
# Line 1: simple output
echo "Hello from Jenkins"
# echo prints text – proves Jenkins can execute commands
# Validation: who am I?
whoami
# Shows which user Jenkins runs as – important for permissions
# Show current directory
pwd
# Shows where Jenkins runs (workspace), not your home folder
# List workspace contents
ls
# Workspace starts empty – useful before cloning repos
# Create a file
echo "This file was created by Jenkins" > jenkins.txt
# Demonstrates that Jenkins can create artifacts
# Display the file
cat jenkins.txt
# Confirms the file exists and its content
# Final log message
echo "Script completed successfully"
- Explanation: Each command is typed to illustrate basic shell operations, verify the Jenkins environment, and produce an artifact (
jenkins.txt). The finalechoprovides a clear log marker for successful completion.
- Click Save
- Click Build Now
- Open Console Output to view the results
✅ What Should Be Seen
- Text printed (
Hello from Jenkins) - Username (output of
whoami) - Jenkins workspace path (output of
pwd) - Confirmation that
jenkins.txtwas created - File content displayed (
cat jenkins.txt)
Concepts
| Concept | Meaning |
|---|---|
| Jenkins job | Automation task |
| Workspace | Safe execution directory |
| Shell step | Real Linux commands |
| Logs | Debugging source |
| Repeatability | Same result every time |
Mandatory Failure Example
exit 1
- Question: “What do you think will happen?”
- Result: The build turns RED. Jenkins stops; no further steps run.
- Explanation:
exit 1signals failure. Jenkins trusts exit codes, which is why failing code can block deployments. This illustrates the principle: Jenkins is “stupid but honest.” It reflects real‑world DevOps behavior.