Certified Jenkins Engineer
Jenkins Setup and Interface
Demo Chained Freestyle Projects
In this tutorial, we’ll walk through splitting a single Freestyle Project into two separate jobs—ASCII Build Job and ASCII Test Job—and chaining them so that tests run only after a successful build. This approach improves modularity, fault isolation, and scalability of your CI pipeline.
Overview of Workflow
Stage | Job Name | Purpose |
---|---|---|
Build | ASCII Build Job | Fetches advice JSON from ADVICESLIP API |
Test | ASCII Test Job | Validates that the advice message has > 5 words |
1. Create the Build Job
From the Jenkins dashboard, click New Item, enter ASCII Build Job, and select Freestyle project.
In the job’s Build section, add an Execute shell step with:
# Build: fetch advice from ADVICESLIP API curl -s https://api.adviceslip.com/advice > advice.json cat advice.json
Save and click Build Now. A successful build shows up on the dashboard:
Inspect the workspace to confirm
advice.json
exists. Example content:{ "slip": { "id": 59, "advice": "Don't be afraid of silly ideas." } }
2. Create the Test Job
Go back to New Item, name it ASCII Test Job, and choose Freestyle project.
In Build → Execute shell, add:
# Ensure the advice has more than 5 words ls advice.json jq -r '.slip.advice' advice.json > advice.message if [ "$(wc -w < advice.message)" -gt 5 ]; then echo "Advice - $(cat advice.message) has more than 5 words" else echo "Advice - $(cat advice.message) has 5 words or less" fi
Save the job. (Currently it will fail if run alone, since
advice.json
is missing.)
3. Chain Jobs with Post-build Actions
Configure ASCII Build Job to trigger ASCII Test Job:
Open ASCII Build Job → Configure.
Scroll to Post-build Actions and choose Build other projects.
Enter
ASCII Test Job
and select Trigger only if build is stable.Save and rebuild ASCII Build Job. Now the dashboard shows the downstream Test job:
4. Diagnose Test Failure
If ASCII Test Job fails, open its dashboard:
Inspect the console output:
Started by upstream project "ascii-build-job" build number 2
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/ascii-test-job
[ascii-test-job] $ /bin/sh -xe /tmp/jenkins*.sh
+ ls advice.json
ls: cannot access 'advice.json': No such file or directory
Build step 'Execute shell' marked build as failure
Finished: FAILURE
The failure happens because advice.json
lives only in the Build job’s workspace.
Next Step
To share artifacts between upstream and downstream Freestyle Projects, install and use the Copy Artifact Plugin. It lets you pull files like advice.json
into the Test job’s workspace before running tests.
References
Watch Video
Watch video content
Practice Lab
Practice lab