I have a trigger to run a build job everytime there's a push to a specific branch of my repository.
If I try to run the build job "manually" (without the trigger) with the command:
# Submit the build job
_cmd = f"gcloud builds submit --no-source --config {config['build']['cloudbuild']} --substitutions {substitutions}"
subprocess.run(_cmd, shell=True, check=True)
it works as expected and completes successfully without any issue. However, if I perform a git push to my repository to do it with the trigger, after the trigger starts the build job and detects the complete structure from my cloudbuild YAML file, it breaks execution on the first step with an error message:
The first step:
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'
The error message:
fatal: destination path '.' already exists and is not an empty directory.
Do you know what the problem might be ?
Thanks in advance!
EDIT:
Tried to clear the directory before the git clone, but still the same result:
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'
When you run your job locally, you use the
--no-source
to not upload file and run the Cloud Build with an empty/workspace
directoryWhen you launch the Cloud Build with trigger, your
/workspace
directory already contain the sources, and your clone target directory isn't empty.You can:
/workspace
.rm -rf
in your/workspace
before running the clone command