Newer to GitLab, by using simple ping test using bash script file I try to fetch the value of the test, success or failure and the duration of the ping.
pingtest.sh file
#!/bin/bash
count=$1
target=$2
testname=$3
ping -c $count $target >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo $testname,Success,$(ping -c $count $target | sed '$!d;s|.*/\([0-9.]*\)/.*|\1|')
else
echo $testname,Failure,$(ping -c $count $target | sed '$!d;s|.*/\([0-9.]*\)/.*|\1|')
fi
.gitlab-ci.yml file
image: centos
stages:
- zero
job run_test_zero:
stage: zero
artifacts:
when: always
paths:
- "report/*"
script:
- echo "TEST NAME|RESULT|DURATION" >> ./report/report.txt
- chmod +x ./scripts/pingtest.sh
- ./scripts/pingtest.sh 3 google.com pinggoolepass >> ./report/report.txt
- ./scripts/pingtest.sh 3 google1.com pinggoolefail >> ./report/report.txt
report.txt file
TEST NAME|RESULT|DURATION
pinggoolepass,Success,6.066
pinggoolefail,Failure,
I'm unable to fetch the duration for failure ping test.
Please anyone suggest and guide me