如何访问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文件以从中获取有用的信息(例如日志文件(

最新更新