如何解决如何访问由GCP云构建步骤创建的日志文件?
我的云构建失败,并在npm test
上超时,并且没有有用的信息发送到stdout。可以在文件中找到完整的日志,但是我找不到在云构建环境中使用ssh的方法。
Already have image: node
> project-client@v3.0.14 test
> jest
ts-jest[versions] (WARN) Version 4.1.0-beta of typescript installed has not been tested with ts-jest. If you're experiencing issues,consider using a supported version (>=3.8.0 <5.0.0-0). Please do not report issues in ts-jest if you are using unsupported versions.
npm ERR! path /workspace/v3/client
npm ERR! command failed
npm ERR! signal SIGTERM
npm ERR! command sh -c jest
npm ERR! A complete log of this run can be found in:
npm ERR! /builder/home/.npm/_logs/2020-11-09T07_56_23_573Z-debug.log
由于我在本地运行测试没有问题,所以我希望查看该2020-11-09T07_56_23_573Z-debug.log
文件的内容,以期获得可能出问题的提示。
是否可以检索文件内容?
- 在云构建环境中使用SSH吗?
- 获取npm以将完整日志打印到stdout吗?
- 以某种方式将日志文件工件保存到云存储中?
解决方法
我在Gitlab CI上的错误管理也遇到了类似的问题,我的解决方法是从那里得到的。
诀窍是将命令嵌入到返回值为0的退出内容中。在此示例
- name: node
entrypoint: "bash"
args:
- "-c"
- |
RETURN_CODE=$$(jtest > log.stdout 2>log.stderr;echo $${?})
cat log.stdout
cat log.stderr
if [ $${RETURN_CODE} -gt 0 ];
then
#Do what you want in case of error,like a cat of the files in the _logs dir
# Break the build: exit 1
else
#Do what you want in case of success. Nothing to continue to the next step
fi
一些解释:
- echo $$ {?}:双重$表示向Cloud Build不使用替代变量,而是忽略替代变量并让Linux命令被解释。
- $?允许您获取上一个命令的退出代码
- 然后测试退出代码,如果> 0,则可以执行操作。最后,我建议中断构建以免继续使用错误的源代码。
- 您可以解析log.stderr文件以获取有用的信息(例如日志文件)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。