SED命令无法在GitLab Runner上正确执行
我有一个脚本需要运行NPM运行测试并捕获测试覆盖范围值 因此,在这里,我试图捕获值36.95
并以Gitlab脚本输出,我打算将其添加为GitLab作业。看来跑步者是GNU。如果我在本地上执行以下脚本,它可以正常工作,就像返回36.95一样。 但是,如果我在gitlab上运行它,它将返回npm运行测试的值
。如何使其与我使用的跑步者兼容。
RES=$(npm test -- --coverage --watchAll=false)
TOTAL=$(sed -E 's/^.* All files \| ([^ ]+) \| .*$/\1/' <<< $RES)
echo "Current test coverage is : " $TOTAL
我认为这里是弦乐(&lt;&lt;&lt;)与跑步者不兼容,这就是为什么它可以在我的本地机器上工作,但在gitlab上也不适用,也许我的脚本也有一些问题。 gitlab pipleline config
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
包含顶部提到的脚本
I have a script which needs to run npm run test and capture test coverage coverage valueso here I am trying to capture the value 36.95
and output it in gitlab script which I am planning to add as a gitlab job. It seems that the runner is gnu. If I execute the below script on my local it works fine as in returns 36.95.
However if I run it on gitlab it returns the value of the npm run test
. How can I make it compattible with the runner I am using.
RES=$(npm test -- --coverage --watchAll=false)
TOTAL=$(sed -E 's/^.* All files \| ([^ ]+) \| .*$/\1/' <<< $RES)
echo "Current test coverage is : " $TOTAL
I think here-string(<<<) is not compatible with the runner which is why it works on my local machine but not on gitlab maybe there is some issue with my script too.
Gitlab pipleline config
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
contains the script mentioned at the top
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以直接将
sed
管道You could just pipe directly to
sed
您可以尝试
&lt;&lt;&lt;&lt;&lt;&let code>
的替代
方案您要
sed
。You can try the alternative to
<<<
Meaning you isolate the line you want to
sed
.