发布脚本
#!/bin/bash prefix="" if `git status | grep "master" &>/dev/null`; then prefix="prod-pj" elif `git status | grep "preview" &>/dev/null`; then prefix="preview-pj" elif `git status | grep "staging" &>/dev/null`; then prefix="staging-pj" else echo "must checkout branch release or test or staging" exit fi function build_tag_push() { git push git pull --tags local new_tag=$(echo ${prefix}-$(date +'%Y%m%d')-$(git tag -l "${prefix}-$(date +'%Y%m%d')-*" | wc -l | xargs printf '%02d')) echo ${new_tag} git tag -a ${new_tag} -m 'create new tag' git push origin ${new_tag} }
自动化http请求远程接受脚本
yum -y install jq
echo "开始自动化测试。。。"
#盘古接口任务触发url
taskexecurl="https://pangu.a.test.com/api/master/v2/public/task/trigger"
# 盘古任务id
taskId="861"
AutoTestNoticeUrl="https://bd-bot.a.test.com/common/webhook/c218559301114c549e349f4d5397908f"
#任务执行结果url
resulturl="http://10.132.34:4033/v2/public/task/trigger/result?taskId=${taskId}&timeout=600"
title="${AppId}自动化测试执行"
#autoTestResult 定义title后的拼接结果
autoTestResult=""
#content
content=""
#标记位
flag=0
execId="0"
#初始化执行接口总数
reportTotal=0
reportPassed=0
reportfailed=0
reporterror=0
##执行盘古测试任务
taskResponse=$(curl -H "Content-Type: application/json" \
-H "group: c0ff6ebd-c2f3-40d5-9aba-037d19a852f5" \
-X POST \
-d '{"taskId": '"${taskId}"', "token": "staging-mdd", "user": "liuyiwei"}' \
"$taskexecurl")
echo "taskResponse:$taskResponse"
taskResponseCode=$(echo "${taskResponse}"|jq '.header.code')
echo "taskResponseCode:$taskResponseCode"
if [[ $taskResponseCode == 0 ]]
then
echo "停一下"
sleep 60s
#执行盘古任务测试结果
taskReport=$(curl -H "group: c0ff6ebd-c2f3-40d5-9aba-037d19a852f5" \
--connect-timeout 10 \
-m 600 \
-X POST "$resulturl")
#取出结果中的code
reportCode=$(echo "${taskReport}" |jq '.header.code')
#取出结果中的total
reportTotal=$(echo "${taskReport}" |jq '.body.total')
#取出结果中的passed
reportPassed=$(echo "${taskReport}" |jq '.body.passed')
#取出结果中的failed
reportfailed=$(echo "${taskReport}" |jq '.body.failed')
#取出结果中的error
reporterror=$(echo "${taskReport}" |jq '.body.error')
#取出结果中的execId
execId=$(echo "${taskReport}" |jq '.body.execId')
echo "报告执行结果:${taskReport}"
echo "reportCode:$reportCode"
echo "reportTotal:$reportTotal"
echo "reportPassed:$reportPassed"
if [[ $reportCode == 0 ]] && [[ $reportTotal == $reportPassed ]]
then
content="自动化测试执行成功!"
echo "接口自动化执行成功!"
elif [[ $reportCode != 0 ]]
then
echo "$resulturl 接口返回失败!"
content="接口:$resulturl 返回失败!code为:$reportCode!!!"
flag=1
elif [[ $reportTotal != $reportPassed ]]
then
echo "自动化测试有失败!"
link="https://pangu.a.test.com/#/jump?task=${taskId}&exec=${execId}"
content="自动化测试有失败,结果请看:${link}"
flag=1
fi
else
flag=1
content="接口:$taskexecurl 接口返回失败!code为:$taskResponseCode!"
echo "接口:$taskexecurl 返回失败!code为:$taskResponseCode!!!"
fi
reportdetail="业务场景总数:$reportTotal 执行成功:$reportPassed 执行失败:$reportfailed 执行异常:$reporterror"
contacts="联系人:${CI_TRIGGER_USER}"
if [[ $flag == 0 ]]
then
autoTestResult="成功!"
echo "接口自动化执行成功!title:$title$autoTestResult content:$content 报告详情:$reportdetail\n$contacts"
curl "${AutoTestNoticeUrl}" -X POST -d '{"title": "'"$title$autoTestResult"'", "content": "'"$content\n$reportdetail\n$contacts"'"}' -H "Content-Type: application/json"
elif [[ $flag == 1 ]]
then
autoTestResult="失败!"
echo "报告中接口有误!title:$title$autoTestResult content:$content 报告详情:$reportdetail\n$contacts"
curl "${AutoTestNoticeUrl}" -X POST -d '{"title": "'"$title$autoTestResult"'", "content": "'"$content\n$reportdetail\n$contacts"'"}' -H "Content-Type: application/json"
exit 1
fi
echo "自动化测试结束。。。"
#!/bin/bash branch_name=$1 npm i --registry=http://xxx case $branch_name in eur*) npm run e-build ;; develop*) npm run test ;; test*) npm run test-build ;; master|release) npm run prd-build ;; *) npm run dev-bd ;; esac cd `dirname $0` set -e
浙公网安备 33010602011771号