【问题标题】:GCP cloudbuild git push triggerGCP cloudbuild git推送触发器
【发布时间】:2021-03-28 05:06:36
【问题描述】:

每次推送到我的存储库的特定分支时,我都有一个运行构建作业的触发器。

如果我尝试使用以下命令“手动”(不使用触发器)运行构建作业:

# Submit the build job
_cmd = f"gcloud builds submit --no-source --config {config['build']['cloudbuild']} --substitutions {substitutions}"
subprocess.run(_cmd, shell=True, check=True)

它按预期工作并成功完成,没有任何问题。 但是,如果我对我的存储库执行 git push 以使用触发器执行此操作,则在触发器启动构建作业并从我的 cloudbuild YAML 文件中检测到完整结构后,它会在第一步中断执行并显示错误消息:

第一步:

steps:
# Clone repo to Cloud Build environment
- name: 'gcr.io/cloud-builders/git'
  args: ['clone',
         '--branch',"$_BRANCH_NAME",
         '${_REPO_URL}', '.',
         '--depth', '1',
         '--verbose']
  id: 'Clone Repo'

错误信息:

fatal: destination path '.' already exists and is not an empty directory.

你知道问题可能是什么吗?

提前致谢!


编辑:

尝试清除git clone前的目录,结果还是一样:

steps:
# Clear Cloud Build environment
- name: 'gcr.io/cloud-builders/git'
  args: ['rm', '-rf', '.']
  id: 'Clear Cloud Build environment'
  
# Clone repo to Cloud Build environment
- name: 'gcr.io/cloud-builders/git'
  args: ['clone',
         '--branch',"$_BRANCH_NAME",
         '${_REPO_URL}', '.',
         '--depth', '1',
         '--verbose']
  waitFor: ['Clear Cloud Build environment']
  id: 'Clone Repo'

【问题讨论】:

    标签: google-cloud-platform gcloud google-cloud-build cloudbuild.yaml


    【解决方案1】:

    当您在本地运行作业时,使用 --no-source 不上传文件并使用空的 /workspace 目录运行 Cloud Build

    当您使用触发器启动 Cloud Build 时,您的 /workspace 目录已经包含源,并且您的克隆目标目录不为空。

    你可以:

    • 要么克隆到另一个目录,然后将内容移动到/workspace
    • 或者在运行克隆命令之前在您的/workspace 中执行rm -rf

    【讨论】:

    • 感谢您的回复 :) 我不确定这是否是您的建议,但我编辑了我的问题以显示我试图做什么。但结果是一样的。它仍然显示相同的错误。我会尝试其他建议,我会尽快提供一些反馈
    • 正常!删除点。像这样args: ['rm', '-rf']
    【解决方案2】:

    显然,通过更改 git clone 的目标目录并更新剩余步骤上的 dir 标签解决了问题:

    steps:
    # Clone repo to Cloud Build environment
    - name: 'gcr.io/cloud-builders/git'
      args: ['clone',
             '--branch',"$_BRANCH_NAME",
             '${_REPO_URL}', 'new_workspace/',    # new directory
             '--depth', '1',
             '--verbose']
      id: 'Clone Repo'
    
    # Create the image for the component 1
    - name: 'gcr.io/cloud-builders/docker'
      args: ['build',
             '-t', 'gcr.io/$_PROJECT_ID/comp_1:$_IMG_TAG', '.']
      dir: 'new_workspace/implementation/pipeline/components/comp_1'  # update with new directory
      id: 'Build Component Image'
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2023-02-21
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      相关资源
      最近更新 更多