charnould
charnould

Reputation: 2907

Use git commands with Google Cloud Builder

I'm trying to use Google Cloud Build with GitHub to make a CI/CD pipeline. However I'm struggling with GCB...

Below, a very simple pipeline :

  1. run npm install --> it works
  2. run npm test--> it works
  3. run npm run css:ALL(rm some files + do some minifying stuff) --> seems to work
  4. run some git commands --> doesn't work

Errors:

Step #3: fatal: not a git repository (or any parent up to mount point /)
Step #3: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

cloudbuild.yaml

steps:
  - name: 'gcr.io/cloud-builders/npm'
    args: ['install']
  # run test
  - name: 'gcr.io/cloud-builders/npm'
    args: ['test']
  # build css files
  - name: 'gcr.io/cloud-builders/npm'
    args: ['run', 'css:ALL']
  # git stuff
  - name: 'gcr.io/cloud-builders/git'
    args: ['add', '-A']
  - name: 'gcr.io/cloud-builders/git'
    args: ['commit', '-m', '"some message"']

Do you have any clue?

My objective is simply to git add all build stuff and push them back in my branch. Thanks

Upvotes: 3

Views: 3424

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 75715

Cloud Build is a great product!! With some boring things... the .git folder is not copied with the source code.

If you run your cloud build manually, simply add an empty .gcloudignore file at the root of your repository. Thanks to it, the .git directory won't be ignored and uploaded with your code.

But this trick doesn't work with trigger. For this, I use this step

steps:
- name: 'gcr.io/cloud-builders/git'
  entrypoint: /bin/bash
  args:
    - -c
    - |
        # Cloud Build doesn't recover the .git file. Thus checkout the repo for this
        git clone --branch $BRANCH_NAME https://github.com/path/to/yourRepo.git /tmp/repo ;
        # Copy only the .git file
        mv /tmp/repo/.git .

Then you can use git, with a valid and existing .git dir

Upvotes: 10

Related Questions