2017-10-20 173 views
0

我有一個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狀態碼並生成報告

回答

0

您是否嘗試過這個插件:Audit2DB

https://wiki.jenkins.io/display/JENKINS/Audit+To+Database+Plugin

它會記錄所有必需的工作細節到數據庫中。當你想創建一個報告時,它會從數據庫中獲取它。 因此,在這種情況下,您需要在腳本失敗時使作業失敗(非零退出)。您也可以在作業完成時將$ http_code設置爲env變量,並將其記錄到數據庫中。

相關問題