在我的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
我不明白为什么前一行运行正常,但这一行却失败了。
我是不是明显漏掉了什么?
任何帮助将不胜感激。
谢谢
2条答案
按热度按时间omjgkv6w1#
curl
可能没有安装在像/usr/bin/
这样的公共位置。我建议你尝试运行curl的完整路径。在你的剧本里:
另一种选择是编辑
/etc/profile
并将curl
附加到PATH
所在的位置。41ik7eoe2#
非常感谢你的回复。你是对的,没有安装curl!通过它的完整路径运行curl,然后修改我的脚本,现在已经解决了这个问题。Thank you!:)