【问题标题】:Add timestamp to Google Cloud Build log output向 Google Cloud Build 日志输出添加时间戳
【发布时间】:2020-04-07 09:38:39
【问题描述】:

我们在Google Cloud Platform 上使用Cloud Build

是否可以在日志输出的每一行添加时间戳?

【问题讨论】:

  • 嘿@Harold L. Brown,我无法清楚地理解你想在这里做什么。你能详细说明吗?您的意思是想在 Cloud Build 中添加某种日志记录语句吗?如果您担心构建日志,您可以随时查看 stackdriver logging --> Cloud Build。在那里您可以找到每个构建步骤及其时间戳。
  • @MethkalKhalawi 我希望每个日志输出语句都带有时间戳。例如:语句应改为2020-04-08T07:46:35+00:00 build finished,而不是build finished。所以我可以更好地猜测我的构建需要多长时间。

标签: logging google-cloud-platform timestamp continuous-integration google-cloud-build


【解决方案1】:

您不能直接使用 Cloud Build 执行此操作,但您可以通过在 linux 上使用 moreutils 包来解决此问题:

gcloud builds submit --config cloudbuild.yaml | ts '[%Y-%m-%d %H:%M:%S]'

这将为您提供如下输出:

[2020-04-08 10:53:53] starting build "50e00fbb-2224-46d4-b13a-6b15a9fbbe3c"
[2020-04-08 10:53:53]
[2020-04-08 10:53:53] FETCHSOURCE
[2020-04-08 10:53:53] Fetching storage object xxxxxxx
[2020-04-08 10:53:53] Copying xxxxxx
/ [1 files][  331.0 B/  331.0 B]                      
[2020-04-08 10:53:53] Operation completed over 1 objects/331.0 B.
[2020-04-08 10:53:53] BUILD
[2020-04-08 10:53:53] Starting Step #0
[2020-04-08 10:53:53] Step #0: Pulling image: ubuntu
[2020-04-08 10:53:53] Step #0: Using default tag: latest
[2020-04-08 10:53:53] Step #0: latest: Pulling from library/ubuntu
[2020-04-08 10:53:53] Step #0: Digest: xxxxxxx
[2020-04-08 10:53:53] Step #0: Status: Downloaded newer image for ubuntu:latest
[2020-04-08 10:53:53] Step #0: docker.io/library/ubuntu:latest

【讨论】:

    【解决方案2】:

    @Methkal Khalawi 上面评论中的解决方案开箱即用:而不是在 GCP 控制台的 CloudBuild 选项卡中查看 CloudBuild 日志,如下所示:

    ... 打开 Logging (Stack Driver) 选项卡并从下拉框中选择 Cloud Build。这将显示您在 Cloud Build 选项卡中看到的相同日志,但现在带有时间戳,如下所示:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-30
      • 2017-04-07
      • 2020-08-18
      • 1970-01-01
      • 2018-07-15
      • 2017-02-04
      • 2016-08-04
      • 2016-08-16
      相关资源
      最近更新 更多