I have a script which needs to run npm run test and capture test coverage coverage value so here I am trying to capture the value 36.95
并将其输出到gitlab脚本中,我计划将其添加为gitlab作业(job).似乎 run 者是gnu.如果我在本地执行下面的脚本,它可以正常工作,如返回36.95.
RES=$(npm test -- --coverage --watchAll=false)
TOTAL=$(sed -E 's/^.* All files \| ([^ ]+) \| .*$/\1/' <<< $RES)
echo "Current test coverage is : " $TOTAL
我认为这里是字符串(<;<;)与runner不兼容,这就是为什么它可以在我的本地机器上运行,但不能在gitlab上运行.也许我的脚本也有问题.
test:
stage: test
image: node:16.13.1
before_script:
- npm i
- npx node -v
- npx npm -v
script:
- echo "running test coverage"
- bash test.sh
test.sh
包含顶部提到的脚本