1. Create a New Freestyle Project
- Log into Jenkins and click New Item.
- Enter generate ASCII artwork as the project name.
- Select Freestyle project and click OK.

2. Configure General Settings
Under General, set up the project metadata:- Description: Generate ASCII artwork using the Cowsay library and AdviceSlip REST API
- Leave Discard old builds, This project is parameterized, and other options at their defaults.
- Source Code Management: None
- Build Triggers: (none)
- Build Environment: Enable Add timestamps to the console output (requires the Timestamp Plugin).



3. Add Build Step: Execute Shell
Choose Add build step → Execute shell and paste this script. It fetches advice, validates it, installs Cowsay, adjusts the PATH, and prints the ASCII art.
Script Breakdown
| Script Section | Purpose |
|---|---|
curl fetch | Download JSON from AdviceSlip API |
jq + wc | Extract text and enforce a minimum of 6 words |
apt-get install cowsay | Install the Cowsay package |
export PATH | Add /usr/games and /usr/local/games to the PATH |
cowsay render | Pipe advice into a random cowsay template to produce artwork |
Sample AdviceSlip API Response
4. Save and Run the Job
- Click Save, then Build Now.
- On the first run, you may see an error because the workspace doesn’t exist yet:

5. Investigate a Failed Build
A common failure occurs when Cowsay isn’t found in the PATH:The Jenkins service user’s default environment may exclude
/usr/games. Always export or globally configure PATH so that Jenkins can locate installed binaries.6. Update the Script and Rebuild
After adding theexport PATH line, save and run Build Now again. Success output:

7. Review Build History and Workspace
You can inspect past runs, access permalinks, and browse the workspace files:

8. (Optional) Configure Global Environment Variables
To avoid repeatingexport PATH in every job:
- Go to Manage Jenkins → Configure System.
- Under Global properties, check Environment variables.
- Add:
- Name:
PATH - Value:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/snap/bin:/usr/games:/usr/local/games
- Name:
When you override
PATH globally, include the full default PATH. Jenkins does not expand environment variables in the value field. Alternatively, adjust /etc/default/jenkins or use the Environment Injector Plugin to append directories.