如果我的shell脚本失败,我如何在Jenkins中生成报告?有没有插件?
问题描述:
我有一个jenkins工作,它将通过运行docker-compose文件在我的CentOS机器中进行部署。这是我的shell脚本的外观?如果我的shell脚本失败,我如何在Jenkins中生成报告?有没有插件?
#!/bin/sh
# Post steps for deployment
# Navigate to deployment scripts
cd /deployment/scripts/v1.0.784
#Execute the uninstall script
./dit_undeploy_all.sh
set +e
#Remove all docker images and containers
docker container rm $(docker ps -a -q) -f
docker rmi $(docker images -a -q)
docker volume rm $(docker volume ls -q)
set -e
#Remove and clear out the folder structure
rm -rf *.*
#Gets all the latest files from Artifactory by reading from teh input file
wget -B https://artifactory.gue.com -i /deployment/scripts/inputFile.txt
# Gives rea/write access
chmod +x *.*
# Execute docker compose file to get all the latest containers
./dit_deploy_all.sh
#Add wait time for the services to be up and running
sleep 60s #Wait 15 sec
# Need to update the URL
./dit_create_policies.sh
#Verify URL Status Code of 200
cd /deployment/scripts
sleep 60s #Wait time 60s
./verifyHttpCode
脚本./verifyHttpCode执行以下操作:
#!/bin/bash
while read LINE; do
curl -o /dev/null --silent --head --write-out '%{http_code}' "$LINE"
echo " $LINE"
done < url-list.txt
部署将验证HTTP状态代码后,所以基本上...什么是TestNG中的shell脚本相当于,我可以使用在Jenkins验证http状态码并生成报告
答
您是否尝试过这个插件:Audit2DB
https://wiki.jenkins.io/display/JENKINS/Audit+To+Database+Plugin
它会记录所有必需的工作细节到数据库中。当你想创建一个报告时,它会从数据库中获取它。 因此,在这种情况下,您需要在脚本失败时使作业失败(非零退出)。您也可以在作业完成时将$ http_code设置为env变量,并将其记录到数据库中。