在我的 Jenkinsfile Groovy 脚本中,我有以下代码;
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
'''
}
}
}
文件的第一部分工作正常,包括命令;
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:]' `
当我运行 Jenkins 构建时失败。
产生以下错误;
line 4: curl: command not found
我不明白为什么前一行运行正常,但这一行却失败了。
我是否遗漏了一些明显的东西?
任何帮助将不胜感激。
谢谢
有可能
curl
没有安装在像 /usr/bin/
这样的公共位置。我建议您尝试通过完整路径运行curl。
$ which curl
/usr/somelocation/curl # <- just an example
然后在你的脚本中:
RESULT=`/usr/somelocation/curl -LI $URL...`
另一个选项是编辑
/etc/profile
并附加到 PATH
无论 curl
所在的位置。
export PATH=$PATH:/usr/somelocation/
非常感谢您的回复。你是对的,curl 没有安装!通过它的完整路径运行curl,然后修改我的脚本现在已经解决了问题。谢谢你! :)