Reputation: 97
In my Jenkinsfile Groovy script, I have the following code;
stage('Test the 500 log URLs') {
steps {
script {
echo 'Testing the URLs from the 500 error access log...'
sh '''#!/bin/bash
while IFS= read -r line; do
URL=`echo $line | awk '{print $2}' | sed 's/http:/https:/' `
RESULT=`curl -LI $URL -o /dev/null -w "%{http_code}\n" -s | tr -d '[:space:]' `
if [[ $RESULT != "200" ]]
then
echo "$RESULT $URL"
fi
done < tests/Smoke/logs_testing/500errors.txt
'''
}
}
}
The first parts of the file work correctly, including the command;
URL=`echo $line | awk '{print $2}' | sed 's/http:/https:/' `
However, the following line;
RESULT=`curl -LI $URL -o /dev/null -w "%{http_code}\n" -s | tr -d '[:space:]' `
fails when I run the Jenkins build.
The following error is produced;
line 4: curl: command not found
I can't see why the previous line ran ok, but this line is failing.
Is there something obvious I'm missing?
Any help would be greatly appreciated.
thanks
Upvotes: 1
Views: 10248
Reputation: 3968
It is possible that curl
was not installed in a common location like /usr/bin/
. I'd suggest you try to run curl via its full path.
$ which curl
/usr/somelocation/curl # <- just an example
Then in your script:
RESULT=`/usr/somelocation/curl -LI $URL...`
Another option is to edit your /etc/profile
and append to PATH
wherever curl
is located.
export PATH=$PATH:/usr/somelocation/
Upvotes: 0