简体   繁体   中英

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-as.netcore/cloudbuild.yaml --dryrun=false clearbooks-rest-as.netcore

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?

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM