In this blog I will be discussing on working on simple Free-Style project
- Seletct Free style project
- Project Name: Generate ASCII Artwork
- Select General Configuration.
- Description:
Generate ASCII Artwork using Cowsay library and AdviceSlip Rest API
- Build Environment -- Add timestamps to the Console Output
- Build Steps -- Execute Shell
# See the list of available environment variables
# Build a message by invoking ADVICESLIP API
curl -s https://api.adviceslip.com/advice > advice.json
cat advice.json
# Test to make sure the advice message has more than 5 words.
cat advice.json | jq -r .slip.advice > advice.message
[ $(wc -w < advice.message) -gt 5 ] && echo "Advice has more than 5 words" || (echo "Advice $(cat advice.message) has 5 words")
# Deploy
sudo apt-get install cowsay -y
echo $PATH
export PATH="$PATH:/usr/games:/usr/local/games
echo $PATH
cat advice.message | cowsay -f $(ls /usr/share/cowsay/cows | shuf -n 1)
- Save and Apply: A work space will be allocated for this pipeline.
- Build the pipeline
- Check the console output of log info
- The pipeline fails because the jenkins is not able to access the system environment variables. Jenkins runs as an isolated environment with jenkins user.
- This can be resolved by envs place after the installation of cowsay.
echo $PATH
export PATH="$PATH:/usr/games:/usr/local/games
echo $PATH
If the multiple jenkins jobs need these envs as dependencies pass them in the environment key-value. For this freestyle project.
In the workspace the file downloaded was stored.
Chained Freestyle Project
The previous shell script has three stages if take them as
- Build
- Test
- Deploy So, lets seperate these into each freestyle job. ### Build job
# Build a message by invoking ADVICESLIP API
curl -s https://api.adviceslip.com/advice > advice.json
cat advice.json
Test Job
It will fail if manually triggered.
Because the build job has seperate workspace and test job has different.
# Test to make sure the advice message has more than 5 words.
cat advice.json | jq -r .slip.advice > advice.message
[ $(wc -w < advice.message) -gt 5 ] && echo "Advice has more than 5 words" || (echo "Advice $(cat advice.message) has 5 words")
Now we chain the build job and test jobs.
Trigger only the build jobs success then test job. Under the build job configuration. Add the test job name in build job post actions save and apply.
lets trigger the build job then look at the test job. Yes now they are linked even though the test job failed. Now Look at Plugins. Some plugins info are below.
Where plugin store and their format, priority.
Installing plugins
To install plugins go to ManageJenkins > Plugin
- Updates
- Available plugins
- installed plugins
Lets install Copy Artifact
for this project.For documentation Copy Artifact
in the build job enable the artifacts copyt to test-job and enable the archive advice.json
file. Save and apply.
In the test job add the build step as first build step for getting the artifacts. To move the build steps use drag-and-drop.
Not the build and test jobs are working fine.
Deploy job
Create deploy job and configure the build step with below and add the prior step as copy artifacts from test-job
only if the testjob is stable. Also give permissions to copy artifacts from the test job.
# Deploy
sudo apt-get install cowsay -y
cat advice.message | cowsay -f $(ls /usr/share/cowsay/cows | shuf -n 1)
If you faced any issues with the deploy-job then try to replicate same as test job configuration.
Finally the three jobs are chained. Now to visualize the chanied jobs
install the Yet another build visualizer
then goto any of the chained project.
Disadvantages of Freestyle pipeline:
- start the jobs and run
systemctl stop jenkins
. It will stop the jobs running. Try 'systemctl start jenkins` check the jobs restarted where they failed. Freestyle project pipelines would not auto-restart.
Lets try to add figerprint to the advice.json and advice.message file. Jenkins will create a MD5 checksum to track the jobs used the file, it only store the checksum not the file itself. Configure it as a post action save and apply.
Now in the build-job page verify the finger print added.
Jenkins Pipeline projects.
- Declarative
- Scripted - most control (require groovy knowledge)
Follow me for more content on DevOps.
Top comments (0)