Hello @everyone, trust you are all doing well. Please I need your help, I am trying to create a FreeStyle Job in Jenkins and the Build failed. It failed because the advice.message file wasn’t created in my workspace - /var/lib/jenkins/workspace/Generate ASCII Artwork and there’s also an issue with the password. I am logged in as the root user on my laptop with sudo -i command. Please, how can I resolve this issue? Thanks in advance for any help. My shell script command and my console output are below.
Shell Script Command
Build A message by invoking the ADVICESLIP API
curl -s https://api.adviceslip.com/advice > advice.json
cat advice.json
Test to make sure that the advice service has more than 5 words.
cat advice.json | jq -r .slip.advice > advice.json
[ $(wc -w < advice.message) -gt 5 ] && echo “Advice has more than 5 words” || (echo “Advice - $(cat advice.message) has 5 words or less” && exit)
Deploy
sudo apt-get install cowsay -y
cat advice.message | cowsay -f $(ls /urs/share/cowsay/cow | shuf -n 1)
Jenkins Job Console Output
05:20:19 Started by user Tunde Admin 05:20:19 Running as SYSTEM 05:20:19 Building in workspace /var/lib/jenkins/workspace/Generate ASCII Artwork 05:20:19 [Generate ASCII Artwork] $ /bin/sh -xe /tmp/jenkins6242414768285851953.sh 05:20:19 + curl -s https://api.adviceslip.com/advice 05:20:20 + cat advice.json 05:20:20 {“slip”: { “id”: 142, “advice”: “If you don’t like the opinion you’ve been given, get another one.”}}+ cat advice.json 05:20:20 + jq -r .slip.advice 05:20:20 /tmp/jenkins6242414768285851953.sh: 8: cannot open advice.message: No such file 05:20:20 + [ -gt 5 ] 05:20:20 /tmp/jenkins6242414768285851953.sh: 8: [: -gt: unexpected operator 05:20:20 + cat advice.message 05:20:20 cat: advice.message: No such file or directory 05:20:20 + echo Advice - has 5 words or less 05:20:20 Advice - has 5 words or less 05:20:20 + exit 05:20:20 + sudo apt-get install cowsay -y 05:20:20 sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper 05:20:20 sudo: a password is required 05:20:20 Build step ‘Execute shell’ marked build as failure 05:20:20 Finished: FAILURE