4
votes

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?

2
guess you need to pass an absolute path for the --config.Martin Zeitler
@MartinZeitler I did that for on the Buid Trigger section and it still doesn't work because it seems to need the source parameter to match yet the Build Trigger definition screen doesn't expose that.Perry Ismangil
What error message or misbehavior do you see?Jeffrey Rennie
@JeffreyRennie I've now solved this by adding dir: parameter and testing locally with the correct parameter to reflect how Cloud Build works. Posted as an answer. Thanks!Perry Ismangil

2 Answers

13
votes

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
0
votes

I was developing a sample project with Spring Boot with App Engine and directory structure is like.

google-cloud
      - appengine-spring-boot
      - appflexengine-spring-boot

below are the cloudbuild.yaml file that is working for me.

steps:
  - name: 'gcr.io/cloud-builders/mvn'
    dir: "appengine-spring-boot"
    #args: [ 'package','-f','pom.xml','-Dmaven.test.skip=true' ]
    args: [ 'clean', 'package']
  - name: "gcr.io/cloud-builders/gcloud"
    dir: "appengine-spring-boot"
    args: [ "app", "deploy" ]
    timeout: "1600s"