问题
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
回答1:
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/
回答2:
Many thanks for you reply. You were right, curl wasn't installed! Running curl via it's full path and then amending my script has now resolved the problem. Thank you! :)
来源:https://stackoverflow.com/questions/53283775/curl-bash-command-not-working-in-jenkinsfile-groovy-script