Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Builder - how to trigger build configuration in a subdirectory?

I'm trying to establish a Google Cloud Builder Build Trigger to autobuild and deploy my ASP .NET Core application to Google AppEngine.

Using the current cloudbuild.yaml:

   steps:
   - name: 'gcr.io/cloud-builders/dotnet'
     args: [ 'publish', '-c', 'Release' ]

   - name: 'gcr.io/cloud-builders/gcloud'
     args: ['app','deploy','./bin/Release/netcoreapp2.1/publish/app.yaml']

I have tested local build working using cloud-build-local tool.

These two approach worked locally:

  1. From the application subdirectory: cloud-build-local --config=cloudbuild.yaml --dryrun=false .
  2. From the repository root: cloud-build-local --config=clearbooks-rest-aspnetcore/cloudbuild.yaml --dryrun=false clearbooks-rest-aspnetcore

The Build Trigger definition seems to partially support config files from a subdirectory of the repository root (approach no 2) however it seems to assume that code always lives in repository root.

How do I configure Cloud Builder to start a build in a subdirectory of the repository?

like image 796
Perry Ismangil Avatar asked Dec 11 '22 05:12

Perry Ismangil


1 Answers

The solution is to update cloudbuild.yaml:

  1. Add the dir: option on the build step
  2. Provide the correct app.yaml location for deploy step

Here is the working cloudbuild.yaml:

steps:
- name: 'gcr.io/cloud-builders/dotnet'
  args: [ 'publish', '-c', 'Release' ]
  dir: 'clearbooks-rest-aspnetcore'

- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app','deploy','clearbooks-rest-aspnetcore/bin/Release/netcoreapp2.1/publish/app.yaml']

When testing locally, run cloud-build-local on repository root, never on the app subdirectory:

cloud-build-local --config=clearbooks-rest-aspnetcore/cloudbuild.yaml --dryrun=false .

This reflects the way Cloud Build works:

  1. Path to correct cloudbuild.yaml
  2. Current directory for source
like image 179
Perry Ismangil Avatar answered May 16 '23 06:05

Perry Ismangil