未找到 Cloud Build“cd”中的更改目录

Ari*_*Ari 2 google-cloud-build cloudbuild.yaml

我正在使用云构建来克隆存储库。我可以确认存储库已成功克隆到云构建/workspace卷。

steps:
  - id: 'Clone repository'
    name: 'gcr.io/cloud-builders/git'
    args: ['clone', $_REPO_URL]
    volumes:
    - name: 'ssh'
      path: /root/.ssh
Run Code Online (Sandbox Code Playgroud)

然后我运行下一步来确认

  - id: 'List'
    name: 'alpine'
    args: ['ls']
Run Code Online (Sandbox Code Playgroud)

它显示存储库位于当前目录中。但是当我尝试cd进入该目录时,该cd命令不起作用并引发错误:

ERROR: build step 3 "alpine" failed: starting step container failed: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "cd <repo-name>": executable file not found in $PATH: unknown
Run Code Online (Sandbox Code Playgroud)

我的最终目标是cd进入存储库并运行一些 git 命令。我稍后使用 alpine,因为git构建器映像不允许我使用cd其中任何一个。

ERROR: build step 3 "alpine" failed: starting step container failed: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "cd <repo-name>": executable file not found in $PATH: unknown
Run Code Online (Sandbox Code Playgroud)

Cai*_*ioT 6

您可以使用 bash 运行任何您想要的命令。这是我在我的一个项目中使用的一个示例:

- name: 'gcr.io/cloud-builders/git'
  id: Clone env repository
  entrypoint: /bin/sh
  args:
  - '-c'
  - |
    git clone git@github.com:xyz/abc.git && \
    cd gitops-env-repo/ && \
    git checkout dev   
Run Code Online (Sandbox Code Playgroud)