【问题标题】:Changing directories in Cloud Build 'cd' no found未找到在 Cloud Build 'cd' 中更改目录
【发布时间】:2021-10-08 14:29:17
【问题描述】:

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

steps:
  - id: 'Clone repository'
    name: 'gcr.io/cloud-builders/git'
    args: ['clone', $_REPO_URL]
    volumes:
    - name: 'ssh'
      path: /root/.ssh

然后我运行下一步确认

  - id: 'List'
    name: 'alpine'
    args: ['ls']

它告诉我存储库在当前目录中。但是当我尝试将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

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

substitutions:
  _REPO_NAME: 'test-repo'
  _REPO_URL: 'git@bitbucket.org:example/test-repo.git'
  _BRANCH_NAME: 'feature/something'

steps:
  - id: 'Clone repository'
    name: 'gcr.io/cloud-builders/git'
    args: ['clone', $_REPO_URL]
    volumes:
    - name: 'ssh'
      path: /root/.ssh

  - id: 'Check Diff'
    name: 'alpine'
    args: ['cd $_REPO_NAME', '&&', 'git checkout $_BRANCH_NAME', '&&', 'git diff main --name-only']

【问题讨论】:

    标签: google-cloud-build cloudbuild.yaml


    【解决方案1】:

    您可以使用 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   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-03
      • 2023-01-11
      • 2016-08-31
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多