【问题标题】:Get Git History in Google Cloud Build Step在 Google Cloud Build 步骤中获取 Git 历史记录
【发布时间】:2020-08-23 09:39:03
【问题描述】:

我正在使用 Google Cloud Build 为我的 Nx 工作区运行 CI。这是 cloudbuild.yaml 文件:

    steps:
      - name: 'gcr.io/cloud-builders/docker'
        id: Test_Affected_Projects
        entrypoint: 'sh'
        args: [
            '-c',
            'docker build --build-arg NPM_TOKEN=$$NPM_TOKEN --file ./test/Dockerfile.test-runner -t mha-test-runner .']
        secretEnv: ['NPM_TOKEN']
    # Remove the docker image
    secrets:
    - kmsKeyName: /path/to/key
      secretEnv:
        NPM_TOKEN: some_key_value

(目前有两个步骤,但为了简洁,我删除了第二步。第二步只是删除了创建的 docker 镜像。)

现在 Docker 映像中的命令运行 Nx 工作区的所有测试。问题是,Nx 有一个很棒的命令,只测试受影响的库。但是要运行命令,项目的 git 历史记录需要可用。

我试图在云构建上下文中获取 git 历史记录,但我无法让它工作。这是我添加的步骤,以尝试让一切正常:

steps:
  - name: 'gcr.io/cloud-builders/git'
    args: ['fetch', '--unshallow']
  - name: 'gcr.io/cloud-builders/docker'
    id: Test_Affected_Projects
    entrypoint: 'sh'
    args: [
        '-c',
        'docker build --build-arg NPM_TOKEN=$$NPM_TOKEN --file ./test/Dockerfile.test-runner -t mha-test-runner .']
    secretEnv: ['NPM_TOKEN']
# Remove the docker image
secrets:
- kmsKeyName: /path/to/key
  secretEnv:
    NPM_TOKEN: some_key_value

应该获取 git 历史记录的新的第一个命令失败了。错误信息说它不是 git repo,所以命令失败。

我的问题是:如何在云构建上下文中获取 git 历史记录,以便在构建/测试过程中使用不同的命令?

【问题讨论】:

  • 触发器是Github App触发器吗?如果是这种情况,您必须事先copy the repo。 GitHub 触发器和 GitHub 应用程序触发器之间的区别是微妙的,但第一个将执行 repo 的浅拷贝,第二个将 Cloud Storage 存档作为源。

标签: google-cloud-build nrwl-nx


【解决方案1】:

我认为这不起作用的原因是您需要将 github 凭据存储在云构建环境中。

我相信这个guide 可以提供帮助。

将允许您这样做,然后您就可以像以前一样拨打git fetch --unshallow

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 2021-02-07
    • 2018-05-10
    • 2020-03-01
    相关资源
    最近更新 更多