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

  1. Open Jenkins
  2. Click New Item
  3. Job name: devops-first-script
  4. Select Freestyle project
  5. Click OK

🧩 Step 2: Add Shell Build Step

  1. Scroll to Build
  2. Click Add build step
  3. 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 final echo provides a clear log marker for successful completion.
  1. Click Save
  2. Click Build Now
  3. 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.txt was created
  • File content displayed (cat jenkins.txt)

Concepts

ConceptMeaning
Jenkins jobAutomation task
WorkspaceSafe execution directory
Shell stepReal Linux commands
LogsDebugging source
RepeatabilitySame 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 1 signals 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.
Back to Blog

Related posts

Read more »

Top 15 DevOps Trends to Watch in 2026

Launched in 2008, the audio streaming platform Spotify has more than 200 million active users worldwide. Initially, Spotify relied on a homegrown container orch...