I am having a steps in Jenkins pipeline to read my test passing result and fail the Stage if rate lower than 95%. Here's the code
sh ''' #!/bin/bash -xe
PASS= `cat index.txt | grep % | tr -d " " | cut -d: -f2 | cut -d% -f1`
if [[ "$PASS" -ge 95 ]]
then
exit 0
else
exit 1
fi
'''
But it constantly gives me an error
16:01:00 + cat index.txt
16:01:00 + grep %
16:01:00 + cut -d% -f1
16:01:00 + tr -d
16:01:00 + cut -d: -f2
16:01:00 + PASS= 100
16:01:00 /home/xxxx/script.sh: 100: not found
What's happened? Anyone could help? Thanks
PASS=
. at the moment, your script is setting PASS to the empty string and then trying to execute the result of thecat .....
(which in your example evaluates to 100). so it is effectivelyPASS="" 100
– cas Aug 19 '19 at 08:10[
instead of double[[
– hellojoshhhy Aug 19 '19 at 08:20if
statement could be replaced by[ "$PASS" -gt 95 ]
. Neitherexit
statements are necessary as the test returns the correct exit status by itself (by virtue of being the last thing executed). – Kusalananda Aug 19 '19 at 08:20$(...)
and that awful pipeline ofcat | grep | tr | cut | cut
instead of just using awk or perl. or maybe sed. – cas Aug 19 '19 at 08:24