DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

Jenkins Runs Commands For Me

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:
    http://localhost:9090

  2. Click New Item

  3. Job name:

devops-first-script
Enter fullscreen mode Exit fullscreen mode
  1. Select Freestyle project
  2. 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

echo "Hello from Jenkins"
Enter fullscreen mode Exit fullscreen mode

Why?

  • echo prints text
  • Proves Jenkins can execute commands
  • First validation Jenkins is working

Line 2

whoami
Enter fullscreen mode Exit fullscreen mode

Why?

  • Shows which user Jenkins runs as
  • Important for permissions (DevOps reality)
  • Explains why some commands fail later

Line 3

pwd
Enter fullscreen mode Exit fullscreen mode

Why?

  • Shows where Jenkins runs
  • Introduces the concept of workspace
  • Jenkins does NOT run in your home folder

Line 4

ls
Enter fullscreen mode Exit fullscreen mode

Why?

  • Lists files in workspace
  • Shows workspace starts empty
  • Important before cloning repos later

Line 5

echo "This file was created by Jenkins" > jenkins.txt
Enter fullscreen mode Exit fullscreen mode

Why?

  • Jenkins creates files just like a human
  • Demonstrates automation creates artifacts
  • > redirects output into a file

Line 6

cat jenkins.txt
Enter fullscreen mode Exit fullscreen mode

Why?

  • Confirms file exists
  • Verifies Jenkins work visually
  • Basic troubleshooting skill

Line 7

echo "Script completed successfully"
Enter fullscreen mode Exit fullscreen mode

Why?

  • Clear log message
  • Professional habit in CI/CD
  • Helps debugging later

▶️ Step 4: Run the Job

  • Click Save
  • Click Build Now
  • Open Console Output

✅ What Should See

  • Text printed
  • Username
  • Jenkins workspace path
  • File created
  • File content displayed

🧠 DevOps Concepts They Just Learned

Concept Meaning
Jenkins job Automation task
Workspace Safe execution directory
Shell step Real Linux commands
Logs Debugging source
Repeatability Same result every time

MANDATORY

exit 1
Enter fullscreen mode Exit fullscreen mode

Ask them:

“What do you think will happen?”

Then run again.


❌ Result

  • Build turns RED
  • Jenkins stops
  • No further steps run

Why?

  • exit 1 = failure
  • Jenkins trusts exit codes
  • This is how bad code blocks deployments

“Jenkins is stupid but honest.
If a command fails, Jenkins stops everything.”

That’s real DevOps.

Top comments (0)